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

33/51

Page

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

How many parameters are required for next_permutation?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <cstdlib>
#include <iostream>
using namespace std;
class X 
{
    public:
    void* operator new(size_t sz) throw (const char*)
    {
        void* p = malloc(sz);
        if (p == 0) 
            throw "malloc() failed";
        return p;
    }
   void operator delete(void* p) 
        {
        cout << "X :: operator delete(void*)" << endl;
        free(p);
    } 
};
class Y 
{
    int filler[100];
    public:
    void operator delete(void* p, size_t sz) throw (const char*)
    {
        cout << "Freeing " << sz << " bytes" << endl;
        free(p);
    };
};
int main() 
{
    X* ptr = new X;
    delete ptr;
    Y* yptr = new Y;
    delete yptr;
}

Select an option to see the answer and solution.

Which is the correct syntax of capturing a variable 'X' by reference and other variable 'Y' by value in lambda expression?

Select an option to see the answer and solution.

Which of the following is correct about tuple_size?

Select an option to see the answer and solution.

Which of the following keyword is used to declare the header file?

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> v; 
    for (int i = 1; i <= 5; i++) 
        v.push_back(i); 
    cout<<v.size()<<endl;
    v.resize(4);
    cout<<v.size()<<endl;
    return 0; 
}

Select an option to see the answer and solution.

Which header file is required for using bitset in your program?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <tuple>
using namespace std;
int main()
{
	tuple <int, char, string> tp = {"Hello", 1, 's'};
	return 0;
}

Select an option to see the answer and solution.

Which of the following is/are advantage(s) of Sequence Container arrays over C-like arrays?

Select an option to see the answer and solution.

Pick out the correct statement.

Select an option to see the answer and solution.

What type of comments does c++ support?

Select an option to see the answer and solution.

What do vectors represent?

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>
#include <functional>
using namespace std;
int op_increase (int i)
{
    return ++i;
}
int main ()
{
    vector<int> a;
    vector<int> b;
    for (int i = 1; i < 4; i++)
    a.push_back (i * 10);
    b.resize(a.size());
    transform (a.begin(), a.end(), b.begin(), op_increase);
    transform (a.begin(), a.end(), b.begin(), a.begin(), plus<int>());
    for (vector<int> :: iterator it = a.begin(); it != a.end(); ++it)
        cout << ' ' << *it;
    return 0;
}

Select an option to see the answer and solution.

Which function is used to get the absolute of a complex number?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
struct A 
{
    virtual void f()  
    { 
        cout << "Class A" << endl; 
    }
};
struct B : A 
{
    virtual void f() 
    { 
        cout << "Class B" << endl;
    }
};
struct C : A 
{
    virtual void f() 
    {
        cout << "Class C" << endl; 
    }
};
void f(A* arg) 
{
    B* bp = dynamic_cast<B*>(arg);
    C* cp = dynamic_cast<C*>(arg);
    if (bp)
        bp -> f();
    else if (cp)
        cp -> f();
    else
        arg -> f();  
};
int main() 
{
    A aobj;
    C cobj;
    A* ap = &cobj;
    A* ap2 = &aobj;
    f(ap);
    f(ap2);
}

Select an option to see the answer and solution.

Which type of relationship is modelled by Aggregation?

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:
    int m;
    Base(int n=0)
    : m(n)
    {
        cout << "Base" << endl;
    }
};
class Derived: public Base
{
    public:
    double d;
    Derived(double de = 0.0)
    : d(de)
    {
        cout << "Derived" << endl;
    }
};
int main()
{
    cout << "Instantiating Base" << endl;
    Base cBase;
    cout << "Instantiating Derived" << endl;
    Derived cDerived;
    return 0;
}

Select an option to see the answer and solution.

Which operator is used to produce a certain number in a specific range?

Select an option to see the answer and solution.

What is the use of is_heap_until() function?

Select an option to see the answer and solution.

Which of the following is correct about bitset and vector of bools?

Select an option to see the answer and solution.