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

25/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>
class XYZ
{
    public:
    void putPri();
    static T ipub;
    private:
    static T ipri; 
};
template <class T>
void XYZ<T>::putPri()
{
    cout << ipri++ << endl;
}
template <class T> T XYZ<T>::ipub = 1;
template <class T> T XYZ<T>::ipri = 1.2;
int main()
{
    XYZ<int> a;
    XYZ<float> b;
    a.putPri();
    cout << a.ipub << endl;
    b.putPri();
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <complex>
using namespace std;
int main()
{
	complex <double> cn(3.0, 4.0);
	cout<<log(cn)<<endl;
	return 0;
}

Select an option to see the answer and solution.

Which of the following will return the new element at the end of container?

Select an option to see the answer and solution.

How are many number of characters available in newname.txt?
#include <stdio.h>
int main ()
{
    FILE * p;
    int n = 0;
    p = fopen ("newname.txt", "rb");
    if (p == NULL) 
        perror ("Error opening file");
    else
    {
        while (fgetc(p) != EOF)
        {
            ++n;
        }
        if (feof(p)) 
        {
            printf ("%d\n", n);
        }
        else
            puts ("End-of-File was not reached.");
        fclose (p);
    }
    return 0;
}

Select an option to see the answer and solution.

Which operator is used to compare the values to find min and max?

Select an option to see the answer and solution.

What will not be called when the terminate() is raised in the constructor?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <new>
#include <iostream>
using namespace std;
struct A 
{
    virtual ~A() {  };
    void operator delete(void* p) 
    {
        cout << "A :: operator delete" << endl;
    }
};
struct B : A 
{
    void operator delete(void* p) 
    {
        cout << "B :: operator delete" << endl;
    }
};
int main() 
{
    A* ap = new B;
    delete ap;
}

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 a = 5;
    int b = 5;
    auto check = [&a]() 
    {
	a = 10;
	b = 10;
    }
    check();
    cout<<"Value of a: "<<a<<endl;
    cout<<"Value of b: "<<b<<endl;
    return 0;
}

Select an option to see the answer and solution.

In which of the following relationship objects of related classes can occur independently?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <array>
 
using namespace std;
 
int main(int argc, char const *argv[])
{
	array<int, 5> arr1;
	arr1.fill(2);
	for(int i=0;i<5;i++)
		cout<<arr1[i];
	cout<<endl;
	return 0;
}

Select an option to see the answer and solution.

What is meant by hash tables in C++?

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 IsOdd (int i)
{
    return ((i % 2) == 1);
}
int main () 
{
    vector<int> myvector;
    myvector.push_back(10);
    myvector.push_back(25);
    myvector.push_back(40);
    myvector.push_back(55);
    vector<int> :: iterator it = find_if (myvector.begin(), 
    myvector.end(), IsOdd);
    cout  << *it << '\n';
    return 0;
}

Select an option to see the answer and solution.

Given below classes which of the following are the possible row entries in vtable of Base class?
class Base
{
    public:
    virtual void function1() {};
    virtual void function2() {};
};
class D1: public Base
{
    public:
    virtual void function1() {};
};
class D2: public Base
{
    public:
    virtual void function2() {};
};

Select an option to see the answer and solution.

Which of the following is the correct syntax of declaring a complex number?

Select an option to see the answer and solution.

What is the use of the flip function in bitset?

Select an option to see the answer and solution.

What do input and output objects support?

Select an option to see the answer and solution.

What is the use of log() function in a complex?

Select an option to see the answer and solution.

What is meant by polymorphism?

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()
{
    double a = 10, b = 5, res;
    char Operator = '/';
    try 
    {
        if (b == 0)
            throw "Division by zero not allowed";
        res = a / b;
        cout << a << " / " << b << " = " << res;
    }
    catch(const char* Str)
    {
        cout << "\n Bad Operator: " << Str;
    }
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
    vector<int> myvector (5);
    int* p = myvector.data();
    *p = 10;
    ++p;
    *p = 20;
    p[2] = 100;
    for (unsigned i = 0; i < myvector.size(); ++i)
        cout << ' ' << myvector[i];
    return 0;
}

Select an option to see the answer and solution.