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

24/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, int N>
class mysequence 
{
    T memblock [N];
    public:
    void setmember (int x, T value);
    T getmember (int x);
};
template <class T, int N>
void mysequence<T,N> :: setmember (int x, T value) 
{
    memblock[x] = value;
}
template <class T, int N>
T mysequence<T,N> :: getmember (int x) 
{
    return memblock[x];
}
int main () 
{  
    mysequence <int, 5> myints;
    mysequence <double, 5> myfloats;
    myints.setmember (0, 100);
    myfloats.setmember (3, 3.1416);
    cout << myints.getmember(0) << '\n';
    cout << myfloats.getmember(3) << '\n';
    return 0;
}

Select an option to see the answer and solution.

What are the vectors?

Select an option to see the answer and solution.

By using which of the following the elements in the associate container can be efficiently accessed?

Select an option to see the answer and solution.

What is the use of middle parameter in the rotate method?

Select an option to see the answer and solution.

What is the output of this C++ program in the "test.txt" file?
#include <fstream>
using namespace std;
int main ()
{
    long pos;
    ofstream outfile;
    outfile.open ("test.txt");
    outfile.write ("This is an apple",16);
    pos = outfile.tellp();
    outfile.seekp (pos - 7);
    outfile.write (" sam", 4);
    outfile.close();
    return 0;
}

Select an option to see the answer and solution.

Which of the following is correct about remove_extent() function?

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 myints[]={ 10, 20, 30, 40, 50 };
    vector<int> myvector (4, 99);
    iter_swap(myints, myvector.begin());
    iter_swap(myints + 3,myvector.begin() + 2);
    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 happens when no argument is supplied to set() function?

Select an option to see the answer and solution.

Which character is used to separate different arguments?

Select an option to see the answer and solution.

What is the use of polar function?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
#include <cstdlib>
#include <exception>
void Funct()
{
    cout << "Funct() was called by terminate()." << endl;
    exit(0);
}
int main()
{
    try
    {
        set_terminate(Funct);
        throw "Out of memory!";
   }
    catch(int)
    { 
        cout << "Integer exception raised." << endl; 
    }
    return 0;
}

Select an option to see the answer and solution.

What can be used to input a string with blank space?

Select an option to see the answer and solution.

Which is dependant on template parameter?

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()
{
    double Op1 = 10, Op2 = 5, Res;
    char Op;
    try 
    {   
        if (Op != '+' && Op != '-' && Op != '*' && Op != '/')
            throw Op;
        switch(Op)
        {
        case '+':
            Res = Op1 + Op2;
            break;
        case '-':
            Res = Op1 - Op2;
            break;
        case '*':
            Res = Op1 * Op2;
            break;
        case '/':
            Res = Op1 / Op2;
            break;
         }
         cout << "\n" << Op1 << " " << Op << " "<< Op2 << " = " << Res;
     }
     catch (const char n)
     {
         cout << n << " is not a valid operator";
     }
     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;
int main()
{
	cout<<rank<remove_all_extents<string[10][20]>::type>::value;
	return 0;
}

Select an option to see the answer and solution.

Which classes are called as mixin?

Select an option to see the answer and solution.

Which is used to handle the exceptions in c++?

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 <ctype.h>
int main ()
{
    char str[] = "ffff";
    long int number;
    if (isxdigit(str[0]))
    {
        number = strtol (str, NULL, 16);
        printf ("%ld\n", number);
    }
    return 0;
}

Select an option to see the answer and solution.

Which header file is used for reading and writing to a file?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
template<class T>
class A
{
   public:
	A(){
		cout<<"Created\n";
	}
	~A(){
		cout<<"Destroyed\n";
	}
};
 
int main(int argc, char const *argv[])
{
	A a;
	return 0;
}

Select an option to see the answer and solution.