C++ Programming - MCQ Practice Questions
C++ MCQs — OOP, STL, pointers, templates for coding rounds & IT exams.
100 questions | 100% Free
What is the default access specifier for class members in C++?
Which keyword is used to create a derived class in C++?
What is the purpose of a virtual function in C++?
Which of the following correctly demonstrates constructor overloading?
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(); }
Which access specifier allows access from derived classes but not from outside?
What is the difference between method overloading and method overriding?
Which of the following is true about abstract classes in C++?
What is the purpose of 'this' pointer in C++?
Which type of inheritance can lead to the Diamond Problem in C++?
What is a copy constructor in C++?
Which of the following demonstrates proper encapsulation?
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; }
What happens when you try to access a private member of a class from outside?
Which of the following is a characteristic of a pure virtual function?
What is the main advantage of using interfaces/abstract classes in C++?
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(); }
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;
In C++, which keyword is used to prevent a class from being inherited?
Which of the following best describes polymorphism in C++?