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

32/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>
using namespace std;
template <typename T, typename U>
void squareAndPrint(T x, U y)
{
    cout << x << x * x << endl;
    cout << y << " " << y * y << endl;
};
int main()
{
    int ii = 2;
    float jj = 2.1;
    squareAndPrint<int, float>(ii, jj);
}

Select an option to see the answer and solution.

Which of the following is a Non-modifying Sequence Operation?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <list>
using namespace std;
int main ()
{
    list<int> mylist;
    list<int> :: iterator it1, it2;
    for (int i = 1; i < 10; ++i) mylist.push_back(i * 1);
        it1 = it2 = mylist.begin();
    advance (it2, 6);
    ++it1;
    it1 = mylist.erase (it1);
    it2 = mylist.erase (it2);
    ++it1;
    --it2;
    mylist.erase (it1, it2);
    for (it1 = mylist.begin(); it1 != mylist.end(); ++it1)
        cout << ' ' << *it1;
    return 0;
}

Select an option to see the answer and solution.

What is the use of is_same() function in C++?

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
{
    public:
        Base(){}
        ~Base(){}
        protected:
        private: 
};
class Derived:public Base
{
    public:
        Derived(){}
        Derived(){}
        private:
        protected:
};
int main()
{
    cout << "The program exceuted" << endl;
}

Select an option to see the answer and solution.

What type of reference should be used in vector arithmetic?

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 ()
{
    cout << min(2, 1) << ' ';
    cout << min('m','m') << '\n';
    return 0;
}

Select an option to see the answer and solution.

Which value is pointed out first in heap?

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:
    void function1() {};
    void function2() {};
};
int main()
{
	Base b;
	cout<<sizeof(b);
	return 0;
}

Select an option to see the answer and solution.

Which of the following(s) is/are the correct way of assigning values to a forward_list f?

Select an option to see the answer and solution.

What is meant by type_info?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <vector> 
#include <algorithm> 
#include <iostream> 
 
using namespace std;
 
int main() 
{ 
    vector<int> v(10, 2); 
    if (all_of(v.cbegin(), v.cend(), [](int i){ return i % 2 == 0; })) 
    { 
	cout << "All numbers are even\n"; 
    } 
    else
    {
	cout << "All numbers are not even\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 <limits>
using namespace std;
int main( )
{
    cout << numeric_limits<float> :: min_exponent << endl;
}

Select an option to see the answer and solution.

What are Engine Adaptors?

Select an option to see the answer and solution.

Which is used to check the error in the block?

Select an option to see the answer and solution.

How many parameters does the throw expression can have?

Select an option to see the answer and solution.

Which of the following syntax is used to convert any variable to its original type?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream> 
#include <vector> 
#include <forward_list>  
 
using namespace std; 
 
int main() 
{ 
    forward_list<int> fl1;
    fl1.assign(5,10);
    for (int&c : fl1)  
        cout << c << " ";
    cout<<endl;
    fl1.insert_after(fl1.begin(), {1,2,3});
    for (int&c : fl1)  
        cout << c << " ";
    cout<<endl; 
    return 0; 
}

Select an option to see the answer and solution.

How the list containers are implemented?

Select an option to see the answer and solution.

How to protect the heap from affecting the memory?

Select an option to see the answer and solution.