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

3/51

Page

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

Which header file is used for generating random numbers?

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 X 
{
    int m;
    public:
    X() : m(10)
    {                                                       
    }
    X(int mm): m(mm)
    {
    }
    int getm()
    {
        return m;
    }
};
class Y : public X 
{
    int n;
    public:
    Y(int nn) : n(nn) {}                                                
    int getn() { return n; }
};
int main()
{
    Y yobj( 100 );
    cout << yobj.getm() << " " << yobj.getn() << endl;
}

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(95);
	bitset<8> b2(45);
	cout<<~b1<<endl;
	cout<<(b1|b2)<<endl;
	cout<<(b1&b2)<<endl;
}

Select an option to see the answer and solution.

Which function is used to check whether a character is a number?

Select an option to see the answer and solution.

How many kinds of parameters are there in C++?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <functional>
#include <numeric>
using namespace std;
int myfunction (int x, int y) 
{
    return x + 2 * y;
}
struct myclass 
{
    int operator()(int x, int y) 
    {
        return x + 3 * y;
    }
} myobject;
int main () 
{
    int init = 100;
    int numbers[] = {10, 20, 30};
    cout << accumulate(numbers, numbers + 3, init);
    cout << endl;
}

Select an option to see the answer and solution.

Which is used to get the input during runtime?

Select an option to see the answer and solution.

What is meant by pure virtual function?

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, 5.0);
	cout<<"Complex number is: "<<real(cn)<<" + "<<imag(cn)<<"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 poly
{
    protected:
    int width, height;
    public:
    void set_values(int a, int b)
    {
        width = a; height = b;
    }
};
class Coutput
{
    public:
    void output(int i);
};
void Coutput::output(int i)
{
    cout << i;
}
class rect:public poly, public Coutput
{
    public:
    int area()
    {
        return(width * height);
    }
};
class tri:public poly, public Coutput
{
    public:
    int area()
    {
        return(width * height / 2);
    }
};
int main()
{
    rect rect;
    tri trgl;
    rect.set_values(3, 4);
    trgl.set_values(4, 5);
    rect.output(rect.area());
    trgl.output(trgl.area());
    return 0;
}

Select an option to see the answer and solution.

Which of the following is correct about Input Iterators?

Select an option to see the answer and solution.

How many types of sequence operations are provided by the C++ algorithm STL?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <memory>
#include <string>
using namespace std;
int main ()
{
    string numbers[] = {"steve", "jobs"};
    pair <string*, ptrdiff_t> result = get_temporary_buffer<string>(2);
    if (result.second>0) 
    {
        uninitialized_copy ( numbers, numbers + result.second, result.first );
        for (int i = 0; i < result.second; i++)
            cout << result.first[i] << " ";
       return_temporary_buffer(result.first);
    }
    return 0;
}

Select an option to see the answer and solution.

What kind of iteration does forward_list provide in C++?

Select an option to see the answer and solution.

Which of the following header file is needed to use vectors in your program?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <string>
#include <iostream>
using namespace std;
void string_permutation( string& orig, string& perm )
{
    if (orig.empty())
    {
        cout<<perm<<endl;
        return;
    }
    for (int i = 0; i < orig.size(); ++i)
    {
        string orig2 = orig;
        orig2.erase(i, 1);
        string perm2 = perm;
        perm2 += orig.at(i);
        string_permutation(orig2, perm2);
    }
}
int main()
{
    string orig = "ter";
    string perm;
    string_permutation(orig, perm);
    return 0;
}

Select an option to see the answer and solution.

What type of class template is list?

Select an option to see the answer and solution.

Pick out the correct statement about vector.

Select an option to see the answer and solution.

How do define the user-defined exceptions?

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> first;
    first.assign (7,100);
    vector<int>::iterator it;
    it=first.begin()+1;
    int myints[] = {1776,7,4};
    cout << int (first.size()) << '\n';
    return 0;
}

Select an option to see the answer and solution.