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

5/6

Page

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

What are the containers?

Select an option to see the answer and solution.

What is the header file used for declaring the standard library algorithms?

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, 30, 20, 10, 10, 20};
    int mycount = count (myints, myints + 8, 10);
    cout << "10 appears " << mycount << " times.\n";
    vector<int> myvector (myints, myints+8);
    mycount = count (myvector.begin(), myvector.end(), 20);
    cout << "20 appears " << mycount  << " times.\n";
    return 0;
}

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 ()
{
    div_t divresult;
 
    divresult = div (38, 5);
    printf ("%d\n", divresult.rem);
    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 () 
{
    vector<int> myvector (4);
    fill (myvector.begin(), myvector.begin() + 2, 3);
    fill (myvector.begin() + 1, myvector.end() - 1, 4);
    for (vector<int> :: iterator it = myvector.begin(); it != myvector.end(); ++it)
        cout << ' ' << *it;
    return 0;
}

Select an option to see the answer and solution.

What are Iterators?

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 Test
{
    public:
    Test();
    virtual ~Test();
};
int main()
{
    Test *ptrvar = NULL;
    try 
    {
        cout << typeid(*ptrvar).name() << endl;
    }
    catch (bad_typeid) 
    {
        cout << "The object is null" << endl;
    }
    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>
using namespace std;
int main () 
{
    int myints[] = {10, 20, 30, 30, 20, 10, 10, 20};  
    int* pbegin = myints;                      
    int* pend = myints + sizeof(myints) / sizeof(int);
    pend = remove (pbegin, pend, 20);      
    for (int* p = pbegin; p != pend; ++p)
        cout << ' ' << *p;
    return 0;
}

Select an option to see the answer and solution.

What is meant by vector in the container library contains?

Select an option to see the answer and solution.

How many macros are used by mathematical functions in the header file <cerrno>?

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 first[] = {5, 10, 15, 20, 25};
    int second[] = {50, 40, 30, 20, 10};
    vector<int> v(10);      
    vector<int> :: iterator it;
    sort (first, first + 5);   
    sort (second, second + 5); 
    it = set_union (first, first + 5, second, second + 5, v.begin());
    cout << int(it - v.begin());
    return 0;
}

Select an option to see the answer and solution.

What are the Sequence Containers?

Select an option to see the answer and solution.

Which of the following is best to include under try block?

Select an option to see the answer and solution.

How many Associative Containers are provided by C++?

Select an option to see the answer and solution.

How many elements does a floating point number is composed of?

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 ()
{
    int n, m;
    n = abs(23);
    m = abs(-11);
    printf ("%d", n);
    printf ("%d", m);
    return 0;
}

Select an option to see the answer and solution.

What is the Standard Template Library?

Select an option to see the answer and solution.

Which header file is required for manipulation of math functions in c++?

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 ()
{
    double param, result;
    param = 5.5;
    result = log (param);
    printf ("%lf", result );
    return 0;
}

Select an option to see the answer and solution.

Pick out the correct method in the c++ standard library algorithm.

Select an option to see the answer and solution.