Vidyalelo
C++ Programming · all questions

C++ miscellaneous
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

1,008

Questions

5/51

Page

Pick an option on a question to see the right answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void show(const vector<int>& vi)
{
    for (size_t i = 0; i < vi.size(); ++i)
        cout << vi[i];
    cout << endl;
}
int main()
{
    vector<int> vi;
    vi.push_back(3);
    vi.push_back(5);
    vi.push_back(5);
    sort(vi.begin(), vi.end());
    show(vi);
    while(next_permutation(vi.begin(), vi.end()))
        show(vi);
    return 0;
}

Select an option to see the answer and solution.

In how many different ways any-container can be constructed?

Select an option to see the answer and solution.

What does this template function indicates?
==================
template<class T, class U>
U func(T a, U b)
{
	cout<<a<<"\t"<<b;
}
==================

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>  
#include <algorithm> 
#include <vector> 
 
using namespace std;
 
int main () 
{
  vector<int> v = {4,2,10,5,1,8};
  sort(v.begin(), v.end());
  if (binary_search(v.begin(), v.end(), 4))
    cout << "found.\n"; 
  else 
  	cout << "not found.\n";
  return 0;
}

Select an option to see the answer and solution.

Identify the correct statement about throw(type).

Select an option to see the answer and solution.

Which operator is used as catch-all handler?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main() 
{
    string s = "a long string";
    s.insert(s.size() / 2, " * ");
    cout << s << endl;
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream> 
#include <vector> 
 
using namespace std; 
 
int main() 
{ 
    vector<int> v; 
    for (int i = 1; i <= 5; i++) 
        v.push_back(i);
    for(int i=0;i<v.size();i++)
    	cout<<v[i]<<" ";
    cout<<endl;
    v.assign(3, 8);
    for(int i=0;i<v.size();i++)
    	cout<<v[i]<<" ";
    cout<<endl;
    return 0; 
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
    vector<int> myvector;
    myvector.push_back(78);
    myvector.push_back(16);
   myvector.front() += myvector.back();
    cout << myvector.front() << '\n';
    return 0;
}

Select an option to see the answer and solution.

What is the default operation of adjacent_difference function in numeric library?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>  
#include <algorithm> 
#include <vector> 
 
using namespace std;
 
bool IsOdd (int i) 
{ 	
	return (i%2)==1; 
}
 
int main () 
{
  vector<int> v = {4,2,10,5,1,8};
  for(int i=0;i<v.size();i++)
  	cout<<v[i]<<" ";
  cout<<endl;
  sort(v.begin(), v.end());
  for(int i=0;i<v.size();i++)
  	cout<<v[i]<<" ";
  return 0;
}

Select an option to see the answer and solution.

How many types of Association can be there between classes?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
template<typename T> 
inline T square(T x)
{
    T result;
    result = x * x;
    return result;
};
int main()
{
    int i, ii;
    float x, xx;
    double y, yy;
    i = 2;
    x = 2.2;
    y = 2.2;
    ii = square(i);
    cout << i << " "  << ii << endl;
    yy = square(y);
   cout << y << " " << yy << endl;
}

Select an option to see the answer and solution.

What type of access does deque and vector provide?

Select an option to see the answer and solution.

What are Iterators?

Select an option to see the answer and solution.

Indexing of bitset variables starts from . . . . . . . .

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class Base
{
    protected:
    int a;
    public:
    Base() 
    { 
        a = 34; 
    }
    Base(int i)
    { 
       a = i; 
    }
    virtual ~Base() 
    { 
        if (a < 0)  throw a; 
    }
    virtual int getA()
    {
       if (a < 0) 
        { 
            throw a;
        }
    }
};
int main()
{
    try
    {
        Base b(-25);
        cout << endl << b.getA();
    }
    catch (int) 
    {
        cout << endl << "Illegal initialization";
    }
}

Select an option to see the answer and solution.

By using which function does the buffer are automatically flushed?

Select an option to see the answer and solution.

Which function is used to access the last element of an array class?

Select an option to see the answer and solution.

How many constructors can present in a class?

Select an option to see the answer and solution.