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

27/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;
int main(int argc, char const *argv[])
{
	vector <int> v = {1,5,23,90,15,35};
	make_heap(v.begin(),v.end());
	cout<<v.front();
}

Select an option to see the answer and solution.

Which is the following is syntactically correct for vector<int> v?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <complex>
using namespace std;
int main()
{
	complex <double> cn(3.0, 4.0);
	auto cnj = conj(cn);
	cout<<"Conjugate of "<<real(cn)<<"+("<<imag(cn)<<")i is: "<<real(cnj)<<"
        +("<<imag(cnj)<<")i"<<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 p 
{
    protected:
    int width, height;
    public:
    void set_values (int a, int b)
    {
        width = a; height = b; 
    }
    virtual int area (void) = 0;
};
class r: public p
{
    public:
    int area (void)
    { 
       return (width * height);
    }
};
class t: public p 
{
    public:
    int area (void)
    {
        return (width * height / 2); 
    }
};
int main () 
{
    r rect;
    t trgl;
    p * ppoly1 = &rect;
    p * ppoly2 = &trgl;
    ppoly1->set_values (4, 5);
    ppoly2->set_values (4, 5);
    cout << ppoly1 -> area() ;
    cout << ppoly2 -> area();
    return 0;
}

Select an option to see the answer and solution.

What kind of pattern is iterator pattern?

Select an option to see the answer and solution.

How many parameters are legal for non-type template?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <deque>
using namespace std;
int main ()
{
    unsigned int i;
    deque<int> mydeque;
    mydeque.push_back (100);
    mydeque.push_back (200);
    mydeque.push_back (300);
    for(deque<int> :: iterator it = mydeque.begin(); it != mydeque.end(); ++it)
    {
    }
    mydeque.clear();
    mydeque.push_back (110);
    mydeque.push_back (220);
    for(deque<int> :: iterator it = mydeque.begin(); it != mydeque.end(); ++it)
        cout << ' ' << *it;
    cout << '\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 <algorithm>
#include <vector>
using namespace std;
int main ()  
{
    int myints[] = {10, 20, 30, 5, 15};
    vector<int> v(myints, myints + 5);
    make_heap (v.begin(), v.end());
    pop_heap (v.begin(), v.end());
    v.pop_back();
    cout << v.front() << '\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>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
	vector <int> v = {90, 47, 34, 23, 4, 35, 67};
	auto it = is_heap_until(v.begin(), v.end());
	for(auto i = v.begin(); i != it; i++)
		cout<<*i<<" ";
}

Select an option to see the answer and solution.

What operator is used to remove the dupplicates in the range?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include<iostream>
#include<stdlib.h>
using namespace std; 
template<class T, class U, class V=double>
class A  
{
    T x;
    U y;
    V z;
};
 
int main()
{
   A<int, int> a;
   A<double, double> b;
   cout << sizeof(a) << endl;
   cout << sizeof(b) << endl;
   return 0;
}

Select an option to see the answer and solution.

When does the next sequence point start?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <queue>
using namespace std;
int main ()
{
    queue<int> myqueue;
    int sum (0);
    for (int i = 1; i <= 10; i++) 
        myqueue.push(i);
    while (!myqueue.empty())
    {
        sum += myqueue.front();
        myqueue.pop();
    }
    cout << sum << endl;
    return 0;
}

Select an option to see the answer and solution.

Which header file is used to manipulate the allocater?

Select an option to see the answer and solution.

What kind of functions are min and max in c++?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
    srand((unsigned)time(0));
    int ran;
    int low = 1, high = 10;
    int range = (high - low) + 1;
    for(int index = 0; index < 1; index++)
    {
        ran = low + int(range * rand() / (RAND_MAX + 1.0));
        cout << ran << endl;
    }
}

Select an option to see the answer and solution.

Which of the following header file is required for forwawrd_list?

Select an option to see the answer and solution.

Pick out the correct statement about multiple inheritances.

Select an option to see the answer and solution.

Which operator is used to compare the elements in heap?

Select an option to see the answer and solution.

Which of the following is correct to interpret Hello World as a single argument?
1. $ ./output 'Hello World'
2. $ ./output Hello World

Select an option to see the answer and solution.