Are you preparing for C++ programming exams, coding interviews, or certifications like CPA or tech roles at companies like Microsoft, Amazon, or Google? This curated list of top 20 C++ MCQ questions with answers covers essential topics such as syntax, OOP concepts, pointers, STL, and more. Perfect for beginners and advanced learners aiming to master C++ programming skills. Each question includes the correct answer and a concise explanation to enhance your understanding. Optimized for SEO, this guide is ideal for C++ MCQs for interviews and C++ competitive programming practice. Let’s dive into the world of C++ in 2025!
These C++ multiple choice questions are sourced from reliable educational platforms and aligned with modern C++ standards (C++11/14/17/20). Practice to achieve 90%+ accuracy!
1. What is C++ primarily known as?
a) Scripting language
b) General-purpose programming language
c) Markup language
d) Database language
Answer: b) General-purpose programming language
Explanation: C++ is a versatile, high-performance language used for system programming, game development, and applications like browsers.
2. Who developed C++?
a) Dennis Ritchie
b) Bjarne Stroustrup
c) Guido van Rossum
d) James Gosling
Answer: b) Bjarne Stroustrup
Explanation: Bjarne Stroustrup created C++ in 1979 at Bell Labs as an extension of C with OOP features.
3. Which keyword is used to define a class in C++?
a) struct
b) class
c) object
d) define
Answer: b) class
Explanation: The class keyword defines a blueprint for objects, e.g., class MyClass { };.
4. What is the output of `cout << sizeof(int);` on a 32-bit system?
a) 2
b) 4
c) 8
d) 16
Answer: b) 4
Explanation: On a 32-bit system, int typically occupies 4 bytes; sizeof returns this size.
5. Which operator is used to access members of a class object using a pointer?
a) .
b) ->
c) ::
d) &
Answer: b) ->
Explanation: The arrow operator -> accesses members via a pointer, e.g., ptr->member, while . is for direct objects.
6. What does the `virtual` keyword do in C++?
a) Defines a constant
b) Enables polymorphism
c) Declares a variable
d) Includes a library
Answer: b) Enables polymorphism
Explanation: virtual allows function overriding in derived classes, supporting runtime polymorphism.
7. Which of the following is NOT a valid C++ access specifier?
a) public
b) private
c) protected
d) internal
Answer: d) internal
Explanation: C++ uses public, private, and protected; internal is not a valid specifier (used in C#).
8. What is the purpose of the `new` operator in C++?
a) Deletes memory
b) Allocates memory dynamically
c) Copies objects
d) Initializes variables
Answer: b) Allocates memory dynamically
Explanation: new allocates memory on the heap, e.g., int* ptr = new int;.
9. What is the output of the following code?
int x = 5; cout << ++x;
a) 5
b) 6
c) 4
d) 7
Answer: b) 6
Explanation: The pre-increment operator ++x increments x to 6 before printing.
10. Which header file is required for input/output operations in C++?
a) `` b) `` c) `` d) `` **Answer: b) ** *Explanation: `` provides `cin`, `cout`, and other I/O functionalities.*
11. What does STL stand for in C++?
a) Standard Template Library b) System Template Language c) Structured Type Library d) Standard Type Language **Answer: a) Standard Template Library** *Explanation: STL provides reusable templates like vectors, lists, and algorithms for efficient programming.*
12. Which of the following is a feature of C++ but not C?
a) Pointers b) Classes c) Functions d) Arrays **Answer: b) Classes** *Explanation: C++ supports OOP with classes, unlike C, which is procedural.*
13. What is the purpose of the `delete` operator?
a) Frees dynamically allocated memory b) Declares a variable c) Initializes an array d) Copies memory **Answer: a) Frees dynamically allocated memory** *Explanation: `delete ptr;` deallocates memory allocated by `new` to prevent memory leaks.*
14. What is function overloading in C++?
a) Defining multiple functions with the same name but different parameters b) Calling a function recursively c) Using default arguments d) Defining virtual functions **Answer: a) Defining multiple functions with the same name but different parameters** *Explanation: Overloading allows functions like `add(int, int)` and `add(float, float)` to coexist.*
15. What is the default access specifier for class members in C++?
a) public b) private c) protected d) friend **Answer: b) private** *Explanation: Class members are private by default, restricting access to within the class.*
16. What is the output of the following code?
```cpp int arr[3] = {1, 2, 3}; cout << arr[3]; ``` a) 3 b) Undefined c) 0 d) Error **Answer: b) Undefined** *Explanation: Accessing `arr[3]` is out of bounds (valid indices are 0 to 2), leading to undefined behavior.*
17. Which keyword is used to inherit a class in C++?
a) extends b) inherits c) : (colon) d) super **Answer: c) : (colon)** *Explanation: Inheritance syntax is `class Derived : public Base {};`.*
18. What does the `const` keyword signify in a function declaration?
a) Function cannot be modified b) Function cannot modify object data c) Function is static d) Function is virtual **Answer: b) Function cannot modify object data** *Explanation: `void func() const;` ensures the function doesn’t alter the object’s state.*
19. Which container is part of the C++ STL?
a) array b) vector c) struct d) class **Answer: b) vector** *Explanation: `vector` is a dynamic array in STL; `array` is fixed-size, introduced in C++11.*
20. What is the purpose of the `this` pointer in C++?
a) Points to the base class b) Refers to the current object c) Allocates memory d) Defines a function **Answer: b) Refers to the current object** *Explanation: `this` is a pointer to the instance calling a member function, used to access object members.*
Why Practice These C++ MCQs?
These top 20 C++ MCQ questions with answers are tailored for C++ coding tests, competitive programming, and job interviews. They cover C++ fundamentals, OOP, pointers, and STL, aligning with real-world applications like game development and system programming. Regular practice sharpens problem-solving and boosts confidence.
Pro Tip for SEO: Share with hashtags like #CPlusPlusMCQs #CppProgramming #CodingInterview on platforms like X, LinkedIn, or Reddit to reach aspiring coders.
Download PDF: [Free C++ MCQs PDF Download] (Host a PDF for easy access).
Need more advanced C++ MCQs, template programming questions, or STL-specific MCQs? Drop a comment below! Keep coding in 2025!