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

11/51

Page

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

What is the use of rank() function in C++?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <array>
using namespace std;
int main(int argc, char const *argv[])
{
	array<int,10> arr = {1,2,3,4,5};
	cout<<"size:"<<arr.size()<<endl;
	cout<<"maxsize:"<<arr.max_size()<<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 <new>
#include <cstdlib>
using namespace std;
const int bsize = 512;
int *pa;
bool allocate = true;
void get_memory() 
{
    cerr << "free store exhausted" << endl;
    delete [] pa;
    allocate = false;
}
void eat_memory(int size) 
{
    int *p = new int[size];
    if (allocate)
        eat_memory(size);
    else
        cerr << "free store addr = " << p << endl;
}
int main()
{
    set_new_handler(get_memory);
    pa = new int[bsize];
    cerr << "free store addr = " << pa << endl;
    eat_memory(bsize);
    return 0;
}

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.capacity()<<endl;
    v.shrink_to_fit();
    cout<<v.capacity()<<endl;
    return 0; 
}

Select an option to see the answer and solution.

What is the operation for .*?

Select an option to see the answer and solution.

What is the property of stable sort function provided by the STL algorithm?

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 funcstatic(int)
{
    int sum = 0;
    sum = sum + 10;
    return sum;
}
int main(void)
{
    int r = 5, s;
    s = funcstatic(r);
    cout << s << 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; 
template <class T, int max>
int arrMin(T arr[], int n)
{
   int m = max;
   for (int i = 0; i < n; i++)
      if (arr[i] < m)
         m = arr[i];
 
   return m;
}
 
int main()
{
   int arr1[]  = {10, 20, 15, 12};
   int n1 = sizeof(arr1)/sizeof(arr1[0]);
 
   char arr2[] = {1, 2, 3};
   int n2 = sizeof(arr2)/sizeof(arr2[0]);
 
   cout << arrMin<int, 10000>(arr1, n1) << endl;
   cout << arrMin<char, 256>(arr2, n2);
   return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <typeinfo>
using namespace std;
class A 
{ 
};
int main()
{ 
    char c; float x;
    if (typeid(c) != typeid(x))
    cout << typeid(c).name() << endl;
    cout << typeid(A).name();
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <map> 
using namespace std;
int main ()
{
    multimap<char, int> mymultimap;
    mymultimap.insert(make_pair('x', 100));
    mymultimap.insert(make_pair('y', 200));
    mymultimap.insert(make_pair('y', 350));
    mymultimap.insert(make_pair('z', 500));
    cout << mymultimap.size() << '\n';
    return 0;
}

Select an option to see the answer and solution.

What is a template?

Select an option to see the answer and solution.

Which are not full container classes in c++?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void Sum(int a, int b, int & c)
{
    a = b + c;
    b = a + c;
    c = a + b;
}
int main()
{
    int x = 2, y =3;
    Sum(x, y, y);
    cout << x << " " << y;
    return 0;
}

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> myvector;
    int sum (0);
    myvector.push_back (100);
    myvector.push_back (200);
    myvector.push_back (300);
    while (!myvector.empty())
    {
        sum += myvector.back();
        myvector.pop_back();
    }
    cout << sum << '\n';
    return 0;
}

Select an option to see the answer and solution.

Which function is used to get the total capacity of a vector?

Select an option to see the answer and solution.

Choose the correct formatted code.

Select an option to see the answer and solution.

What is a pure virtual function in C++?

Select an option to see the answer and solution.

What is the use of apply() function in Valarray?

Select an option to see the answer and solution.

What is the use of proj() function?

Select an option to see the answer and solution.

Which function is used to insert an element into heap?

Select an option to see the answer and solution.