iGET

C++ Programming - MCQ Practice Questions

C++ MCQs — OOP, STL, pointers, templates for coding rounds & IT exams.

100 questions | 100% Free

Q.1Easy

What is the default access specifier for class members in C++?

Q.2Easy

Which keyword is used to create a derived class in C++?

Q.3Easy

What is the purpose of a virtual function in C++?

Q.4Medium

Which of the following correctly demonstrates constructor overloading?

Q.5Medium

What will be the output of the following code? class Base { public: virtual void display() { cout << "Base"; } }; class Derived : public Base { public: void display() { cout << "Derived"; } }; int main() { Base *b = new Derived(); b->display(); }

Q.6Easy

Which access specifier allows access from derived classes but not from outside?

Q.7Medium

What is the difference between method overloading and method overriding?

Q.8Medium

Which of the following is true about abstract classes in C++?

Q.9Easy

What is the purpose of 'this' pointer in C++?

Q.10Medium

Which type of inheritance can lead to the Diamond Problem in C++?

Q.11Medium

What is a copy constructor in C++?

Q.12Medium

Which of the following demonstrates proper encapsulation?

Q.13Hard

What is the output of the following code? class A { public: A() { cout << "A "; } ~A() { cout << "~A "; } }; class B : public A { public: B() { cout << "B "; } ~B() { cout << "~B "; } }; int main() { B obj; return 0; }

Q.14Easy

What happens when you try to access a private member of a class from outside?

Q.15Medium

Which of the following is a characteristic of a pure virtual function?

Q.16Medium

What is the main advantage of using interfaces/abstract classes in C++?

Q.17Hard

Consider the following code: class Base { protected: int x = 10; }; class Derived : private Base { public: void display() { cout << x; } }; int main() { Derived d; d.display(); }

Q.18Hard

What is the output of operator overloading in the following context? class Complex { public: int real, imag; Complex operator+(const Complex &c) { Complex temp; temp.real = real + c.real; temp.imag = imag + c.imag; return temp; } }; Complex c1, c2, c3; c1 = {1, 2}; c2 = {3, 4}; c3 = c1 + c2;

Q.19Easy

In C++, which keyword is used to prevent a class from being inherited?

Q.20Easy

Which of the following best describes polymorphism in C++?

C++ Programming MCQs – Free Practice Tests | iGET | iGET