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

22/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 <class T>
inline T square(T x)
{
    T result;
    result = x * x;
    return result;
};
template <>
string square<string>(string ss)
{
    return (ss+ss);
};
int main()     
{
    int i = 4, ii;
    string ww("A");
    ii = square<int>(i);
    cout << i << ii;
    cout << square<string>(ww) << endl;
}

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 array[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
void swap(int x, int y)
{
    int temp = array[x];
    array[x] = array[y];
    array[y] = temp;
    return;
}
void printArray(int size)
{
    int i;
    for (i = 0; i < size; i++)
        cout << array[i] << " ";
    cout << endl;
    return;
}
void permute(int k, int size)
{
    int i;
    if (k == 0)
        printArray(size);
    else
    {
        for (i = k - 1;i >= 0;i--)
        {
            swap(i, k - 1);
            permute(k - 1, size);
            swap(i, k - 1);
        }
    }
    return;
}
int main()
{
    permute(3, 3);
    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[])
{
	A *a;
	a->func();
	return 0;
}

Select an option to see the answer and solution.

Which of the following is correct about any() function in bitset?

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 MyInterface 
{
    public:
    virtual void Display() = 0;
};
class Class1 : public MyInterface 
{
    public:
    void Display() 
    {
        int  a = 5;
        cout << a;
    }
};
class Class2 : public MyInterface 
{
    public:
    void Display()
    {
        cout <<" 5" << endl;
    }
};
int main()
{
    Class1 obj1;
    obj1.Display();
    Class2 obj2;
    obj2.Display();
    return 0;
}

Select an option to see the answer and solution.

How many vector container properties are there in c++?

Select an option to see the answer and solution.

What is the use of tie() function?

Select an option to see the answer and solution.

What does this template function indicates?
==================
template<class T>
void func(T a)
{
	cout<<a;
}
==================

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 myfunction (int i, int j)
{ 
    return (i < j);
}
struct myclass {
bool operator() (int i, int j)
{
    return (i < j);
} 
} myobject;
int main () 
{
    int myints[] = {10, 9, 8};
    vector<int> myvector (myints, myints + 3);
    sort (myvector.begin(), myvector.begin() + 2);
    sort (myvector.begin() + 1, myvector.end(), myfunction);
    sort (myvector.begin(), myvector.end(), myobject);
    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 is bitset in C++?

Select an option to see the answer and solution.

What is another name of full specialization?

Select an option to see the answer and solution.

What will happen when a programs throws any other type of exception other than specified?

Select an option to see the answer and solution.

Pick out the correct statement about permutation.

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>  
#include <utility>
 
using namespace std;
 
int main () 
{
  pair <int,int>p;
  p = make_pair(1,2);
  cout<<"Pair(first,second) = ("<<p.first<<","<<p.second<<")\n";
  return 0;
}

Select an option to see the answer and solution.

Which of the following(s) can be used to access the last element of a vector v?

Select an option to see the answer and solution.

What is the use of RAII in c++ programming?

Select an option to see the answer and solution.

Which function is used to check whether a character is a tab or space?

Select an option to see the answer and solution.

What can be passed by non-type template parameters during compile time?

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 "My exception";
    }
} myex;
int main () 
{
    try
    {
        throw myex;
    }
    catch (exception& e)
    {
        cout << e.what() << endl;
    }
    return 0;
}

Select an option to see the answer and solution.

Which header file is required to use tuples in your program?

Select an option to see the answer and solution.