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

6/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>
#include <string>
#include <tuple>
using namespace std;
int main()
{
	tuple <int, string> tp1;
	tuple <int, string> tp2;
	tp1 = make_tuple(0, "Hello");
	tp2 = make_tuple(1, "World");
	auto tp3 = tuple_cat(tp1, tp2);
	cout<<"("<<get<0>(tp3)<<", "<<get<1>(tp3)<<", "<<get<2>(tp3)<<", 
        "<<get<3>(tp3)<<")"<<endl;
	return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code if the following arguments are executed on terminal?
===============program.cpp=============
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    for(int i=0;i<argc;i++)
	cout<<argv[i]<<"\n";
}
=======================================
================commands===============
$ g++ program.cpp -o output
$ ./output Hello World
=======================================

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 = -1;
    char *ptr;
    ptr = new char[256];
    try 
    {
        if (x < 0)
        {
            throw x;
        }
        if (ptr == NULL)
        {
            throw " ptr is NULL ";
        }
    }
    catch (...) 
    {
        cout << "Exception occurred: exiting "<< endl;
    }
    return 0;
}

Select an option to see the answer and solution.

When do we call that resource is leaked?

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);
}
int main () 
{
    int myints[] = {10, 20, 20, 20, 30, 30, 20, 20, 10};
    vector<int> myvector (myints, myints + 9);
    vector<int> :: iterator it;
    it = unique (myvector.begin(), myvector.end());                                
    myvector.resize( distance(myvector.begin(), it) );
    unique (myvector.begin(), myvector.end(), myfunction);
    for (it = myvector.begin(); it != myvector.end(); ++it)
        cout << ' ' << *it;
    return 0;
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include<iostream> 
#include<iterator> 
#include<vector> 
using namespace std; 
int main() 
{ 
    vector<int> ar = { 1, 2, 3, 4, 5 }; 
    vector<int>::iterator ptr = ar.begin(); 
    ptr = advance(ptr, 2);
    cout << *ptr << 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;
int main ()
{
    int first[] = {5, 10, 15, 20, 25};
    int second[] = {50, 40, 30, 20, 10};
    vector<int> v(10);
    vector<int> :: iterator it;
    sort (first, first + 5);
    sort (second, second + 5);
    it = set_union (first, first + 5, second, second + 5, v.begin());  
    v.resize(it-v.begin());
    for (it = v.begin(); it != v.end(); ++it)
        cout << ' ' << *it;
    cout << '\n';
    return 0;
}

Select an option to see the answer and solution.

Which objects information is loaded in locale object?

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 X 
{
    public:
    int a;
	void f(int b) 
	{
		cout<< b << endl;
	}
};
int main() 
{
    int X :: *ptiptr = &X :: a;
    void (X :: * ptfptr) (int) = &X :: f;
    X xobject;
    xobject.*ptiptr = 10;
    cout << xobject.*ptiptr << endl;
    (xobject.*ptfptr) (20);
}

Select an option to see the answer and solution.

Which of the following is correct about the first parameter of the main function?

Select an option to see the answer and solution.

What of the following is the equivalent statement for the functor call,
x = f(arg1, arg2);
where f is a functor and arg1 and arg2 are the arguments required by the functors?

Select an option to see the answer and solution.

Which function is used increment the iterator by a particular value?

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;
int main()
{
    cout<<extent<remove_all_extents<string[10][20][30]>::type>::value;
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <queue>
using namespace std;
int main ()
{
    priority_queue<int> mypq;
    mypq.push(10);
    mypq.push(20);
    mypq.push(15);
    cout  << mypq.top() << endl;
    return 0;
}

Select an option to see the answer and solution.

What is a function template?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <locale>
using namespace std;
int main()
{
    locale mylocale("");
    cout.imbue( mylocale );
    cout << (double) 3.14159 << endl;
    return 0;
}

Select an option to see the answer and solution.

Which function is used to check whether a character is an alphabet or number?

Select an option to see the answer and solution.

Which function is used to check whether the vector is empty or not?

Select an option to see the answer and solution.

What is the use of adapter in STL in c++?

Select an option to see the answer and solution.