A
Here, you will find a collection of MCQ questions on C++. Go through these questions to enhance your preparation for upcoming examinations and interviews.
To check the correct answer, simply click the View Answer button provided for each question.
Have your own questions to contribute? Click the button below to share your MCQs with others!
+ Add QuestionA
A
A
#include<iostream>
using namespace std;
class A {
public:
A()
{ cout << " The constructor of class A is called." << endl; }
};
class B {
public:
B()
{ cout << " The constructor of class B is called." << endl; }
};
class C: public A, public B {
public:
C()
{ cout << " The constructor of class C is called." << endl; }
};
int main()
{
C c;
return 0;
}
A
#include<iostream>
using namespace std;
class A {
int arr[10];
};
class B: public A { };
class C: public A { };
class D: public B, public C {};
int main(void)
{
cout << sizeof(D);
return 0;
}
A
#include<iostream>
using namespace std;
class A {
private:
int val;
public:
A(int v = 0) : val(v) {}
void display() { cout << "val = " << val << endl;}
};
class B {
private:
int val;
public:
B(int v) : val(v) {}
operator A() const { return A(val); }
};
void f(A a)
{ a.display(); }
int main() {
B b(5);
f(b);
f(55);
return 0;
}
A
A
A
#include<iostream>
using namespace std;
class A {
public:
void show()
{ cout <<" show() method of class A"; }
};
class B : public A {
public:
void show()
{ cout <<" show() method of class B"; }
};
class C: public B {
};
int main(void)
{
C c;
c.show();
return 0;
}
A
A
#include <iostream>
using namespace std;
class A
{
int s;
public:
#define ABC(A::s)
};
int main(int argc, char const *argv[])
{
cout << "Hello world";
return 0;
}
If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.
Share Your MCQ