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

31/51

Page

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

What are binary functors?

Select an option to see the answer and solution.

Why do we need relationships between classes?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>  
#include <utility>
#include <string>
 
using namespace std;
 
int main () 
{
  pair <int,int> p1(1,2);
  pair <int,int> p2(3,4);
  cout<<"Pair(first,second) = ("<<p1.first<<","<<p1.second<<")\n";
  p1.swap(p2);
  cout<<"Pair(first,second) = ("<<p1.first<<","<<p1.second<<")\n";
  return 0;
}

Select an option to see the answer and solution.

What is meant by permutation in c++?

Select an option to see the answer and solution.

Which operators are used in the free store?

Select an option to see the answer and solution.

Which algorithm is used in subtract_with_carry_engine?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include<iostream> 
#include<iterator> 
#include<vector> 
using namespace std; 
int main() 
{ 
    vector<int> ar = { 1, 2, 3, 4, 5 }; 
    vector<int>::iterator ptr = ar.begin(); 
    ptr = next(ptr, 3);
    cout << *ptr << 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 <exception>
using namespace std;
struct MyException : public exception
{
    const char * what () const throw ()
    {
        return "C++ Exception";
    }
};
int main()
{
    try
    {
        throw MyException();
    }
    catch(MyException& e)
    {
        cout << "Exception caught" << std::endl;
        cout << e.what() << std::endl;
    }
    catch(std::exception& e)
    {
    }    
}

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> myvector (5);
    fill (myvector.begin(), myvector.begin() + 4, 5);
    fill (myvector.begin() + 3,myvector.end() - 2, 8);
    for (vector<int> :: iterator it = myvector.begin();
        it != myvector.end(); ++it)
    cout << ' ' << *it;
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>  
#include <utility>
 
using namespace std;
 
int main () 
{
  pair <int,int> p(1,2);
  cout<<"Pair(first,second) = ("<<p.first<<","<<p.second<<")\n";
  return 0;
}

Select an option to see the answer and solution.

Which operator is used to create the user-defined streams in c++?

Select an option to see the answer and solution.

What is the use of swap() function in array class?

Select an option to see the answer and solution.

Which operator is used to allocate the memory?

Select an option to see the answer and solution.

Which is used to describe the function using placeholder types?

Select an option to see the answer and solution.

What is the syntax of class template?

Select an option to see the answer and solution.

What is the correct statement about lambda expression?

Select an option to see the answer and solution.

In nested try-catch block, if the inner catch block gets executed, then . . . . . . . .

Select an option to see the answer and solution.

Which of the header file is used for array type manipulation?

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()
{
	cout<<extent<remove_extent<string[10][20]>::type>::value;
	cout<<extent<remove_extent<string[10][20][30]>::type>::value;
	return 0;
}

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 Test1 
{ 
};
class Test2 : public Test1 { };
void Funct();
int main()
{
    try
    {
        Funct();
    }
    catch (const Test1&)
    {
        cerr << "Caught a exception" << endl;
    }
    return 0;
}
void Funct()
{
    throw Test2();
}

Select an option to see the answer and solution.