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

17/51

Page

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

Subsequent elements are moved in terms of . . . . . . . . when an element in inserted in vector?

Select an option to see the answer and solution.

Sets are implemented using . . . . . . . .

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main()
{
	cout<<is_array<int>::value;
	cout<<is_array<char[10]>::value;
	cout<<is_array<string>::value;
	return 0;
}

Select an option to see the answer and solution.

Which of the following operations can be performed on a pair?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <exception>
using namespace std;
void myunexpected () 
{
    cout << "unexpected handler called\n";
    throw;
}
void myfunction () throw (int,bad_exception) 
{
    throw 'x';
}
int main (void)
{
    set_unexpected (myunexpected);
    try 
    {
        myfunction();
    }    
    catch (int) 
    { 
        cout << "caught int\n"; 
    }
    catch (bad_exception be) 
    { 
        cout << "caught bad_exception\n"; 
    }
    catch (...) 
    { 
        cout << "caught other exception \n"; 
    }
    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;
template<typename type>
class TestVirt
{
    public:
    virtual type TestFunct(type Var1)
    {
        return Var1 * 2;
    }
};
int main()
{
    TestVirt<int> Var1;
    cout << Var1.TestFunct(100) << endl;
    return 0;
}

Select an option to see the answer and solution.

Which of the following is correct about swap()?

Select an option to see the answer and solution.

Which function is used to check whether a character is tab or space or whitespace control code(\n,\r,etc.)?

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 stu
{
    protected:
    int rno;
    public:
    void get_no(int a)
    {
        rno = a;
    }
    void put_no(void)
    {
    }
};
class test:public stu
{
    protected:
    float part1,part2;
    public:
    void get_mark(float x, float y)
    {
        part1 = x;
        part2 = y;
    }
    void put_marks()
    {
    }
};
class sports
{
    protected:
    float score;
    public:
    void getscore(float s)
    {
        score = s;
    }
    void putscore(void)
    {
    }
};
class result: public test, public sports
{
    float total;
    public:
    void display(void);
};
void result::display(void)
{
    total = part1 + part2 + score;
    put_no();
    put_marks();
    putscore();
    cout << "Total Score=" << total << "\n";
}
int main()
{
    result stu;
    stu.get_no(123);
    stu.get_mark(27.5, 33.0);
    stu.getscore(6.0);
    stu.display();
    return 0;
}

Select an option to see the answer and solution.

Which type of list a Forward_list sequence container implements?

Select an option to see the answer and solution.

Which operator is used to take OR of two bitset variables?

Select an option to see the answer and solution.

How many levels are there in exception safety?

Select an option to see the answer and solution.

Which of the following is the correct way of declaring a tuple?

Select an option to see the answer and solution.

To which type does the numeric limits are suitable?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <fstream>
using namespace std;
int main () 
{
    int length;
    char * buffer;
    ifstream is;
    is.open ("sample.txt", ios :: binary );
    is.seekg (0, ios :: end);
    length = is.tellg();
    is.seekg (0, ios :: beg);
    buffer = new char [length];
    is.read (buffer, length);
    is.close();
    cout.write (buffer, length);
    delete[] buffer;
    return 0;
}

Select an option to see the answer and solution.

What will happen when we use void in argument passing?

Select an option to see the answer and solution.

At which time does the static_cast can be applied?

Select an option to see the answer and solution.

Which of the following library is used to do 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>
#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();
    v.push_back(99); push_heap (v.begin(), v.end());
    sort_heap (v.begin(), v.end());
    for (unsigned i = 0; i < v.size(); i++)
        cout << ' ' << v[i];
    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; 
int main()
{
    try
    {
        try
        {
            throw 20;
        }
        catch (int n)
        {
            cout << "Inner Catch\n";
            throw;
        }
    }
    catch (int x)
    {
        cout << "Outer Catch\n";
    }
    return 0;
}

Select an option to see the answer and solution.