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

12/51

Page

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

Which type of relationship is modelled by Composition?

Select an option to see the answer and solution.

Which of the following describes the protected access specifier?

Select an option to see the answer and solution.

Which is used to use a function from one source file to another?

Select an option to see the answer and solution.

Which is used for formatting purpose in c++?

Select an option to see the answer and solution.

Which is the correct way of handling arguments with spaces?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <set>
using namespace std;
int main()
{
    set<int> tst;
    tst.insert(12);
    tst.insert(21);
    tst.insert(32);
    tst.insert(31);
    set<int> :: const_iterator pos;
    for(pos = tst.begin(); pos != tst.end(); ++pos)
    cout << *pos << ' ';
    return 0;
}

Select an option to see the answer and solution.

What happens when no argument is supplied to flip() function?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <algorithm>
using namespace std;
int main () 
{
    int myints[] = {1, 2, 3};
    sort (myints, myints + 3);
    do 
    {
    } while ( next_permutation(myints, myints + 3) );
    cout << myints[0] << ' ' << myints[1] << ' ' << myints[2] << '\n';
    return 0;
}

Select an option to see the answer and solution.

How the size of a vector increases once it is full?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include<type_traits>
using namespace std;
class Base
{
    public:
};
int main()
{
	Base b;
	cout<<sizeof(b);
	return 0;
}

Select an option to see the answer and solution.

Which of the things does not require instantiation?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main ()
{
    string mystr;
    float price = 0;
    int quantity = 0;
    cout << "Enter price: ";
    getline (cin, mystr);
    stringstream(mystr) >> price;
    cout << "Enter quantity: ";
    getline (cin, mystr);
    stringstream(mystr) >> quantity;
    cout << "Total price: " << price * quantity << endl;
    return 0;
}

Select an option to see the answer and solution.

Which of the following can derived class inherit?

Select an option to see the answer and solution.

Which interface determines how your class will be used by another program?

Select an option to see the answer and solution.

What is the use of the function "showbase"?

Select an option to see the answer and solution.

How many runtime error messages associated with exception?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
    try
    {
        try
        {
            throw 20;
        }
        catch (int n)
        {
            cout << "Inner Catch\n";
        }
    }
    catch (int x)
    {
        cout << "Outer Catch\n";
    }
    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> a (3, 0);
    vector<int> b (5, 0);
    b = a;
    a = vector<int>();
    cout << "Size of a " << int(a.size()) << '\n';
    cout << "Size of b " << int(b.size()) << '\n';
    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; 
template <typename T>
void fun(const T&x)
{
    static int count = 0;
    cout << "x = " << x << " count = " << count;
    ++count;
    return;
}
 
int main()
{
    fun<int> (1); 
    cout << endl;
    fun<int>(1); 
    cout << endl;
    fun<double>(1.1);
    cout << endl;
    return 0;
}

Select an option to see the answer and solution.

Which of the following is the correct syntax of accessing the first element of a pair p?

Select an option to see the answer and solution.