How to use the C++ MCQ Quiz
- 1. Choose the length10 random C++ questions, or all 25.
- 2. AnswerTap an option. You see straight away whether it's right, with a one-line reason.
- 3. ReviewFinish to get your score and a list of every question with the correct answer.
What the questions cover
- Basics: integer division, iostream, references and const member functions.
- OOP: struct vs class, virtual functions, pure virtual functions and abstract classes, virtual destructors, overloading and which operators can't be overloaded.
- Memory: the Rule of Three, RAII, unique_ptr, shared_ptr and weak_ptr, and delete vs delete[].
- Modern C++: std::move, auto, range-based for loops and lambdas.
- STL and templates: std::sort complexity, map vs unordered_map, vector growth, priority_queue and template functions.
This quiz is about C++. For plain C topics such as pointers to pointers, malloc and format strings, take the separate C programming MCQ quiz.
A sample question explained
Why should a base class with virtual functions have a virtual destructor? Suppose Base* p = new Derived(); and later delete p;. If Base's destructor isn't virtual, only Base's destructor runs, so whatever Derived allocated is never cleaned up. Formally that is undefined behaviour. Marking the destructor virtual makes delete call Derived's destructor first, then Base's.
The code questions in this quiz were compiled and run with g++ to confirm their output. For example, int a = 5; int& r = a; r++; cout << a; prints 6, because r is just another name for a. For more questions where you predict output, try the Guess the Code Output quiz.
Frequently asked questions
Which C++ standard is assumed?
C++17, with features from C++11 onwards such as auto, lambdas, smart pointers and move semantics.
Is this the same as the C programming quiz?
No. This one covers C++ features like classes, references and the STL. The C quiz covers C.
Who wrote the questions?
Uncodemy, for placement and interview practice. They aren't from any official exam.
Is the C++ MCQ quiz free to take?
Yes. The C++ MCQ quiz lets you answer every question with no form. At your first score screen we ask for your name and WhatsApp number once; after that, the C++ MCQ quiz and all other Uncodemy tools stay open.