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

13/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;
template<typename type> 
class Test
{
    public:
    Test()
    {
    };
    ~Test()
    {
    };
    type Funct1(type Var1)
    {
        return Var1;
    }
    type Funct2(type Var2)
    {
        return Var2;
    }
};
int main()
{
    Test<int> Var1;
    Test<float> Var2;
    cout << Var1.Funct1(200) << endl;
    cout << Var2.Funct2(3.123) << 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 <functional>
#include <algorithm>
using namespace std;
int main ()
{
    int first[] = {10, 40, 90};
    int second[] = {1, 2, 3};
    int results[5];
    transform ( first, first + 5, second, results, divides<int>());
    for (int i = 0; i < 3; i++)
        cout << results[i] << " ";
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
	bitset<8> b1(20);
	cout<<b1.none();
	cout<<b1.any();
}

Select an option to see the answer and solution.

Which interface in the container is required for storage management?

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 PrintSequence(int StopNum)
{
    int Num;
    Num = 1;
    while (true)
    {
        if (Num >= StopNum)
            throw Num;
        cout << Num << endl;
        Num++;
    }
}
int main(void)
{
    try
    {
        PrintSequence(2);
    }
    catch(int ExNum)
    {
        cout << "exception: " << ExNum << endl;
    }
    return 0;
}

Select an option to see the answer and solution.

What will happen when introduce the interface of classes in a run-time polymorphic hierarchy?

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 BaseClass 
{
    int i;
    public:
    void setInt(int n);
    int getInt();
};
class DerivedClass : public BaseClass
{
    int j;
    public:
    void setJ(int n);
    int mul();
};
void BaseClass::setInt(int n)
{
    i = n;
}
int BaseClass::getInt()
{
    return i;
}
void DerivedClass::setJ(int n)
{
    j = n;
}
int DerivedClass::mul()
{
    return j * getInt();
}
int main()
{
    DerivedClass ob;
    ob.setInt(10);       
    ob.setJ(4);          
    cout << ob.mul();    
    return 0;
}

Select an option to see the answer and solution.

How many types are there in binary heaps?

Select an option to see the answer and solution.

Which function is invoked when we try to throw an exception that is not supported by a function?

Select an option to see the answer and solution.

What is the use of vector arithmetic in c++?

Select an option to see the answer and solution.

Which parameter is legal for non-type template?

Select an option to see the answer and solution.

Which of the following is used for generic programming?

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.resize(4);
    cout<<v.capacity()<<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<type_traits>
using namespace std;
class Base
{
   public:
    virtual void function1() {};
    virtual void function2() {};
};
int main()
{
	Base b;
	cout<<sizeof(b);
	return 0;
}

Select an option to see the answer and solution.

To which type of class, We can apply RTTI?

Select an option to see the answer and solution.

In how many ways templates concept can be used?

Select an option to see the answer and solution.

The if..else statement can be replaced by which operator?

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()
{
    try
   {
        throw 1;
    }
    catch (int a)
    {
        cout << "exception number:  " << a << endl;
        return 0;
    }
    cout << "No exception " << endl;
    return 0;
}

Select an option to see the answer and solution.

Which function is used to check whether a given sequence is heap or not?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <exception>
using namespace std;
class myexception: public exception
{
    virtual const char* what() const throw()
    {
        return "exception arised";
    }
} myex;
int main () 
{
    try
    {
        throw myex;
    }
    catch (exception& e)
    {
        cout << e.what() << endl;
    }
    return 0;
}

Select an option to see the answer and solution.