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

7/51

Page

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

How many sets of requirements are need in designing a container?

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;
int main () 
{
    try
    {
        int* myarray = new int[1000];
        cout << "allocated";
    }
    catch (exception& e)
    {
        cout << "Standard exception: " << e.what() << endl;
    }
    return 0;
}

Select an option to see the answer and solution.

What kind of library is Standard Template Library?

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<<is_same<int,char>::value;
	cout<<is_same<char[10], char[10]>::value;
	cout<<is_same<char*[10], string>::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 ()
{
    queue<int> myqueue;
    myqueue.push(12);
    myqueue.push(75);  
    myqueue.back() -= myqueue.front();
    cout << myqueue.back() << 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 <numeric>
using namespace std;
int myfunction (int x, int y) 
{
    return x + 2 * y;
}
struct myclass 
{
    int operator()(int x, int y) 
    {
        return x + 3 * y;
    }
} myobject;
int main () 
{
    int init = 100;
    int numbers[] = {10, 20, 30};
    cout << accumulate (numbers, numbers + 3, init, minus<int>() );
    cout << endl;
    return 0;
}

Select an option to see the answer and solution.

What is the difference between begin() and cbegin() in vectors?

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<<rank<remove_extent<string[10][20]>::type>::value;
	cout<<rank<remove_extent<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 <stdio.h> 
#include <ctype.h>
int main ()
{
    int i = 0;
    char str[] = "C";
    while (str[i])
    {
        if (isalpha(str[i])) 
            printf ("alphabetic");
        else 
            printf ("not alphabetic");
        i++;
    }
    return 0;
}

Select an option to see the answer and solution.

Which of the header file is used to implement algorithms provided by C++ STL?

Select an option to see the answer and solution.

To what type of object does the container can be instantiated?

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 var = -12;
   try {
      cout<<"Inside try\n";
      if (var < 0)
      {
        throw var;
        cout<<"After throw\n";
      }
   }
   catch (char var ) {
      cout<<"Exception Caught\n";
   }
 
   cout<<"After catch\n";
   return 0;
}

Select an option to see the answer and solution.

What is Valarray in C++?

Select an option to see the answer and solution.

What are Distributions in C++?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main()
{
    srand((unsigned)time(0));
    int ran;
    for (int i = 0; i < 2; i++)
    {
        ran = (rand() % 10) + 1;
        cout << ran;
    }
}

Select an option to see the answer and solution.

How many parameters are available in srand function?

Select an option to see the answer and solution.

Which one is used to refer to program elements in any translation units?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <functional>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main () 
{
    vector <string*> numbers;
    numbers.push_back ( new string ("one") );
    numbers.push_back ( new string ("two") );
    numbers.push_back ( new string ("three") );
    vector <int> lengths ( numbers.size() );
    transform (numbers.begin(), numbers.end(), lengths.begin(), 
    mem_fun(&string :: length));
    for (int i = 0; i < 3; i++) 
    {
        cout << lengths[i];
    }
    return 0;
}

Select an option to see the answer and solution.

What can be improved by formatting the source code?

Select an option to see the answer and solution.

How many types of class relationships are there?

Select an option to see the answer and solution.