Vidyalelo
C++ Programming · all questions

Standard Template Library (STL) in C++
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

109

Questions

3/6

Page

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

What is the purpose of the 'std::forward_list' container in C++ STL?

Select an option to see the answer and solution.

Which algorithm in C++ STL is used to sort a range of elements using quicksort?

Select an option to see the answer and solution.

What is the purpose of the 'std::array' container in C++ STL?

Select an option to see the answer and solution.

Which algorithm in C++ STL is used to compute the sum of elements in a range?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <stdio.h>
#include <math.h>
int main ()
{
    printf ("%lf\n", fmod (5.3, 2) );
    printf ("%lf\n", fmod (18.5, 4.2) );
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <typeinfo>
#include <iostream>
using namespace std;
class shape
{
    public:
    virtual void myvirtualfunc() const {}
};
class mytriangle: public shape
{
    public:
    virtual void myvirtualfunc() const
    {   
    };
};
int main()
{
    shape shape_instance;
    shape &ref_shape = shape_instance;
    try 
    {
        mytriangle &ref_mytriangle = dynamic_cast(ref_shape);
    }
    catch (bad_cast) 
    {
        cout << "Caught: bad_cast exception\n";
    }
    return 0;
}

Select an option to see the answer and solution.

Which is best for coding the standard library for c++?

Select an option to see the answer and solution.

Where are standard exception classes grouped?

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 () 
{
    vector<int> myvector;
    for (int i = 1; i < 6; ++i) 
        myvector.push_back(i);
    reverse(myvector.begin(), myvector.end());
    for (vector<int> :: iterator it = myvector.begin(); it != myvector.end(); ++it)
        cout << ' ' << *it;
    return 0;
}

Select an option to see the answer and solution.

How many parameters are used in frexp function?

Select an option to see the answer and solution.

Pick out parameter for rehash method in unordered_set in c++?

Select an option to see the answer and solution.

What are Container Adaptors?

Select an option to see the answer and solution.

What are Unordered Associative Containers?

Select an option to see the answer and solution.

How does the limits.h header file can be represented in C++?

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;
    v.assign( 10, 42 );
    for (int i = 0; i < v.size(); i++) 
    {
        cout << v[i] << " ";
    }
}

Select an option to see the answer and solution.

Pick out the wrong header file.

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <stdio.h>    
#include <stdlib.h>
int main ()
{
    char s[] = "365.24 29.53";
    char* p;
    double d1, d2;
    d1 = strtod (s, &p);
    d2 = strtod (p, NULL);
    printf ("%.2f\n", d1/d2);
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <list>
#include <queue>
using namespace std;
int main()
{
    queue<char> q;
    q.push('a');
    q.push('b');
    q.push('c');
    cout << q.front();
    q.pop();
    cout << q.front();
    q.pop();
    cout << q.front();
    q.pop();
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <list>
#include <string>
#include <iostream>
using namespace std ;
typedef list<string> LISTSTR; 
int main()
{
    LISTSTR :: iterator i;
    LISTSTR test;
    test.insert(test.end(), "one");
    test.insert(test.end(), "two");
    LISTSTR test2(test);
    LISTSTR test3(3, "three");
    LISTSTR test4(++test3.begin(),
    test3.end());
    cout << "test:";
    for (i =  test.begin(); i != test.end(); ++i)
        cout << " " << *i << endl;
    cout << "test:";
    for (i =  test2.begin(); i != test2.end(); ++i)
        cout << " " << *i << endl;
    cout << "test:";
    for (i =  test3.begin(); i != test3.end(); ++i)
        cout << " " << *i << endl;
    cout << "test:";
    for (i =  test4.begin(); i != test4.end(); ++i)
        cout << " " << *i << endl;
}

Select an option to see the answer and solution.

What is the use of <exception> header

Select an option to see the answer and solution.