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

29/51

Page

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

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class class0 
{
    public:
    virtual ~class0(){}
    protected:
    char p;
    public:
    char getChar();
};
class class1 : public class0 
{
    public:
    void printChar();
};
void class1::printChar()
{
    cout  << "True" << endl;
}
int main() 
{
    class1 c;
    c.printChar();
    return 1;
}

Select an option to see the answer and solution.

What is the signature of math in function using command line arguments?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <stdio.h>
#include <ctype.h>
int main ()
{
    int i = 0;
    int cx = 0;
    char str[] = "Hello, welcome!";
    while (str[i])
    {
        if (ispunct(str[i])) cx++;
            i++;
    }    
    printf ("%d\n", cx);
    return 0;
}

Select an option to see the answer and solution.

Where exception are handled?

Select an option to see the answer and solution.

By seeing which operator thus this C++ program stops getting the input?
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
    char ch;
    streambuf * p;
    ofstream os ("test.txt");
    pbuf = os.rdbuf();
    do {
        ch = cin.get();
        p -> sputc(ch);
    } while (ch != '.');
    os.close();
    return 0;
}

Select an option to see the answer and solution.

Which of the following statements regarding absolute and concrete classes in C++ is correct?

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
{
    public:
	A(){
		cout<<"Created\n";
	}
	~A(){
		cout<<"Destroyed\n";
	}
};
 
int main(int argc, char const *argv[])
{
	A <int>a;
	return 0;
}

Select an option to see the answer and solution.

What can go wrong in resource management on c++?

Select an option to see the answer and solution.

What is the main purpose of the constructor?

Select an option to see the answer and solution.

Which is used to solve the memory management problem 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;
int main()
{
    int x = 5;
    auto check = []() -> bool 
    {
	if(x == 0)
		return false;
	else
		return true;
    };
    cout<<check()<<endl;
    return 0;
}

Select an option to see the answer and solution.

What do all STL containers define?

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); 
 
    vector<int> :: const_iterator i;
    i = v.begin();
    *i = 3;
   	for (i = v.begin(); i != v.end(); ++i) 
        cout << *i << " ";
    cout<<endl;
 
    return 0; 
}

Select an option to see the answer and solution.

Which function is used to return the minimum element in the range?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <complex>
using namespace std;
int main()
{
	complex <double> cn(3.0, 5.0);
	cout<<"Absolute value is: "<<abs(cn)<<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 <typeinfo>
#include <exception>
using namespace std;
class base 
{ 
    virtual void f(){} 
};
class derived : public base {};
int main () 
{
    try 
    {
        base* a = new base;
        base* b = new derived;
        cout << typeid(*a).name() <v '\t';
        cout << typeid(*b).name();
    } 
    catch (exception& e) 
    { 
        cout << "Exception: " << e.what() << 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 <string>
using namespace std;
class A
{
	int a;
    public:
	virtual void func() = 0;
};
 
class B: public A
{
   public:
	void func(){
		cout<<"Class B"<<endl;
	}	
};
 
int main(int argc, char const *argv[])
{
	B b;
	b.func();
	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 () 
{
    int myints[] = {1, 2, 3, 4 ,5};
    vector<int> v(myints, myints + 5);
    v.push_back(33); 
    push_heap (v.begin(),v.end());
    cout << v.front() << '\n';
    sort_heap (v.begin(),v.end());
    return 0;
}

Select an option to see the answer and solution.

What does the sequence adaptor provide?

Select an option to see the answer and solution.

Which statement is used to catch all types of exceptions?

Select an option to see the answer and solution.