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

23/51

Page

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

What is the use of empty() function in array classes?

Select an option to see the answer and solution.

How many groups of output of operation are there in c++?

Select an option to see the answer and solution.

What kind of error can arise when there is a problem with memory?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <map>
using namespace std;
int main ()
{
    try {
        map<char, int> mymap;
        map<char, int> :: iterator it;
        mymap['a'] = 50;
        mymap['b'] = 100;
        mymap['c'] = 150;
        mymap['d'] = 200;
        it = mymap.find('b');
        mymap.erase (it);
        mymap.erase (mymap.find('d'));
        cout << mymap.find('a') -> second << '\n';
    }
    catch (...) 
    {
        cout << "Unknown exception: " << endl;
    }
    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 BaseClass 
{
    public:
    virtual void myFunction()
    {
        cout << "1";
    }
};
class DerivedClass1 : public BaseClass 
{
    public:
    void myFunction()
    {
        cout << "2";
    }
};
class DerivedClass2 : public DerivedClass1 
{
    public:
    void myFunction()
    {
        cout << "3";
    }
};
int main()
{
    BaseClass *p;
    BaseClass ob;
    DerivedClass1 derivedObject1;
    DerivedClass2 derivedObject2;
    p = &ob;
    p -> myFunction();
    p = &derivedObject1;
    p -> myFunction();
    p = &derivedObject2;
    p -> myFunction();
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <cctype>
using namespace std;
int main(int argc, char const *argv[])
{
    char arr[12] = "H3ll0\tW0r1d";
    for(int i=0;i<12;i++)
    {
	cout<<(bool)isprint(arr[i]);
    }
}

Select an option to see the answer and solution.

Which of the following class template are based on arrays?

Select an option to see the answer and solution.

What must be specified when we construct an object of class ostream?

Select an option to see the answer and solution.

What is the correct syntax of constructing any using copy initialization?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
	bitset<8> b1(20);
	cout<<b1.test(1);
	cout<<b1.test(2);
}

Select an option to see the answer and solution.

What should present when throwing a object?

Select an option to see the answer and solution.

Which is the correct syntax of defining a pure virtual function?

Select an option to see the answer and solution.

What does the cerr represent?

Select an option to see the answer and solution.

What is the use of reset function in bitset?

Select an option to see the answer and solution.

What is the use of random_shuffle() function of STL algorithm?

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 ()
{
    int n;
    for (n = 5; n > 0; n--)
    {
        cout << n;
        if (n == 3)
            break;
    }
    return 0;
}

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 ()
{
    int myints[] = {2, 4, 6, 8, 10};
    vector<int> v(myints, myints + 5);
    make_heap (v.begin(),v.end());
    cout  << v.front() << '\n'; 
    return 0;
}

Select an option to see the answer and solution.

What is a comment in c++?

Select an option to see the answer and solution.

Which header is need to be used with function objects?

Select an option to see the answer and solution.

Pick the correct statement.

Select an option to see the answer and solution.