C++ MCQ
C++ MCQ
Sample MCQ: What is the correct file extension for a C++ program?
o A) .cpp
o B) .cs
o C) .c
o D) .py
Answer: A) .cpp
2. Data Types
4. Operators
6. Loops
Sample MCQ: Which loop in C++ executes at least once, regardless of the
condition?
o A) for
o B) while
o C) do-while
o D) foreach
Answer: C) do-while
7. Functions
Sample MCQ: Which of the following correctly declares a function in C++ that
returns an integer?
o A) int myFunction()
o B) function int myFunction()
o C) myFunction()
o D) def int myFunction()
Answer: A) int myFunction()
10. Inheritance
Sample MCQ: How do you declare that a class Child inherits from class Parent
in C++?
o A) class Child extends Parent
o B) class Child : public Parent
o C) class Child inherits Parent
o D) class Child = Parent
Answer: B) class Child : public Parent
11. Polymorphism
Sample MCQ: Which keyword is used to allow a derived class to override a base
class method in C++?
o A) override
o B) virtual
o C) abstract
o D) new
Answer: B) virtual
12. Encapsulation
Sample MCQ: Which of the following access specifiers in C++ allows members to
be accessible only within the same class?
o A) public
o B) private
o C) protected
o D) global
Answer: B) private
13. Abstraction
14. Templates
20. Pointers
21. References
23. Multithreading
24. Namespaces