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

18/51

Page

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

The switch statement is also called as?

Select an option to see the answer and solution.

Which container is used to keep priority based elements?

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()
{
    int a = 5;
    auto check = [](int x) 
    {
	if(x == 0)
		return false;
	else
		return true;
    };
    cout<<check(a)<<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>
#include <vector>
using namespace std;
bool mygreater (int i,int j) 
{
    return (i > j);
}
int main () 
{
    int myints[] = {10, 20, 30, 30, 20, 10, 10, 20};
    vector<int> v(myints, myints + 8);
    pair<vector<int> :: iterator, vector<int> :: iterator> bounds;
    sort (v.begin(), v.end());
    bounds = equal_range (v.begin(), v.end(), 20);
    cout  << (bounds.first - v.begin());
    cout << " and " << (bounds.second - v.begin()) << '\n';
    return 0;
}

Select an option to see the answer and solution.

What is the function of shift()?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
template<class T>
class A
{
	T a;
    public:
	A(){}
	~A(){}
};
 
int main(int argc, char const *argv[])
{
	A <char>a1;
	A <int>a2;
	A <double>a3;
	cout<<sizeof(a1)<<endl;
	cout<<sizeof(a2)<<endl;
	cout<<sizeof(a3)<<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 Cat
{
    public:
    int age;
    int weight;
};
int main()
{
    Cat f;
    f.age = 56;
    cout << "Gates is " ;
    cout << f.age << " years old.\n";
}

Select an option to see the answer and solution.

Which classes can have vtable?

Select an option to see the answer and solution.

What are the operators available in C++ for dynamic allocation and de-allocation of memories?

Select an option to see the answer and solution.

How many types of templates are there in c++?

Select an option to see the answer and solution.

Which access specifier is used where one wants data members to be accessed by other classes but not from outside objects?

Select an option to see the answer and solution.

What is sequence container arrays?

Select an option to see the answer and solution.

Which of the following queue container can expand or shrink from both directions?

Select an option to see the answer and solution.

Which type of heap is implemented in STL heap?

Select an option to see the answer and solution.

What is meant by container ship?

Select an option to see the answer and solution.

From where does the template class derived?

Select an option to see the answer and solution.

Which function is used to position back from the end of file object?

Select an option to see the answer and solution.

Which of the following is the correct syntax of using pair p?

Select an option to see the answer and solution.

How one can restrict a function to throw particular exceptions only?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <stdio.h>
int main ()
{
    int n;
    FILE * p;
    char buffer [5];
    p = fopen ("myfile.txt", "w+");
    for ( n = 'A' ; n <= 'D' ; n++)
    fputc ( n, p);
    rewind (p);
    fread (buffer, 1, 5, p);
    fclose (p);
    buffer[3] = '\0';
    puts (buffer);
    return 0;
}

Select an option to see the answer and solution.