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

14/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;
int main ()
{
    int i;
    cout << "Please enter an integer value: ";
    cin >> i + 4;
    return 0;
}

Select an option to see the answer and solution.

Map is implemented using . . . . . . . .

Select an option to see the answer and solution.

How many types of exception handling are there in c++?

Select an option to see the answer and solution.

Which are instances of a class with member function operator() when it is defined?

Select an option to see the answer and solution.

What is the use of fill() function in array class?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include<iostream>
#include <fstream>
using namespace std;
int main () 
{
    ofstream outfile ("test.txt");
    for (int n = 0; n < 100; n++)
    {
        outfile << n;
        outfile.flush();
    }
    cout << "Done";
    outfile.close();
    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>
#include <algorithm>
using namespace std;
int main() 
{
    string s = "spaces in text";
    s.erase(remove(s.begin(), s.end(), ' ' ), s.end() ) ;
    cout << s << endl;
}

Select an option to see the answer and solution.

What is the use of emplace() function?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include<iostream>
#include<any>
using namespace std;
int main()
{
	int a = 5;
	any var = a;
	cout<<var<<endl;
	return 0;
}

Select an option to see the answer and solution.

Which one is always faster in writing on C++?

Select an option to see the answer and solution.

Which operator is used to access the nth bit in a bitset?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <stdexcept>
#include <limits>
#include <iostream>
using namespace std;
void MyFunc(char c)
{
    if (c < numeric_limits<char>::max())
        return invalid_argument;
}
int main()
{
    try
    {
        MyFunc(256);
    }
    catch(invalid_argument& e)
    {
        cerr << e.what() << endl;
        return -1;
    }
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
template <class T>
class A
{
    public:
    A(int a): x(a) {}
    protected:
    int x;
};
template <class T>
class B: public A<char>
{
    public:
    B(): A<char>::A(100) 
    {
        cout << x * 2 << endl;
    }
};
int main()
{
    B<char> test;
    return 0;
}

Select an option to see the answer and solution.

What is meant by sequence point?

Select an option to see the answer and solution.

Where does the member should be defined if it is used in the program?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;  
template<int n> 
struct funStruct
{
    static const int val = 2*funStruct<n-1>::val;
};
 
template<> 
struct funStruct<0>
{
    static const int val = 1 ;
};
 
int main()
{
    cout << funStruct<10>::val << endl;
    return 0;
}

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 square (int *x)
{
    *x = (*x + 1) * (*x);
}
int main ( )
{
    int num = 10;
    square(&num);
    cout << num;
    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 <stdlib.h>
#include <time.h>
int main ()
{
    srand (time(NULL));
    printf ("Random number: %d\n", rand() % 100);
    srand (1);
    return 0;
}

Select an option to see the answer and solution.

What is the use of get() function in tuples?

Select an option to see the answer and solution.

What is the difference between begin() and rbegin()?

Select an option to see the answer and solution.