C++ Quiz
C++ extends C with object-oriented features and is used for games, systems software and performance-critical code. Expect questions about syntax, pointers, references, classes, constructors and the standard template library.
What this quiz covers
- Syntax and data types
- Pointers and references
- Classes and constructors
- Inheritance and STL
Study tip: Draw pointers and references as boxes and arrows on paper; it makes memory questions much clearer.
Questions, answers and explanations
1. Who developed C++?
- Dennis Ritchie
- Bjarne Stroustrup
- James Gosling
- Guido van Rossum
Answer: Bjarne Stroustrup
C++ was developed by Bjarne Stroustrup in 1979.
2. C++ is an extension of which programming language?
- C
- Java
- Python
- Pascal
Answer: C
C++ was developed as an extension of the C programming language.
3. Which file extension is commonly used for C++ source files?
- .cpp
- .java
- .py
- .js
Answer: .cpp
The .cpp extension is commonly used for C++ source files.
4. Which function is the entry point of every C++ program?
- main()
- start()
- run()
- begin()
Answer: main()
Every C++ program begins execution from the main() function.
5. Which symbol is used to end a statement in C++?
- .
- :
- ;
- ,
Answer: ;
Every C++ statement ends with a semicolon.
6. Which keyword is used to define a class in C++?
- class
- Class
- struct
- object
Answer: class
The class keyword is used to define a class.
7. Which operator is used to access members of an object?
- .
- ->
- ::
- #
Answer: .
The dot operator accesses members of an object.
8. Which header file is required for cout and cin?
- <iostream>
- <stdio.h>
- <string>
- <math.h>
Answer: <iostream>
The iostream header provides cin and cout.
9. Which object is used to display output in C++?
- cout
- cin
- echo
Answer: cout
cout is used to display output to the console.
10. Which object is used to receive input from the keyboard?
- cin
- cout
- input
- scanf
Answer: cin
cin is used to receive input from the user.
11. Which keyword is used for inheritance in C++?
- extends
- inherits
- :
- implements
Answer: :
Inheritance in C++ is specified using a colon (:) followed by the access specifier.
12. Which access specifier allows members to be accessed from anywhere?
- public
- private
- protected
- friend
Answer: public
Public members can be accessed from outside the class.
13. Which access specifier allows access only within the class?
- private
- public
- protected
- default
Answer: private
Private members are accessible only inside the class.
14. Which keyword is used to create an object dynamically?
- new
- malloc
- create
- dynamic
Answer: new
The new keyword allocates memory dynamically for objects.
15. Which keyword releases dynamically allocated memory?
- delete
- free
- remove
- destroy
Answer: delete
The delete keyword deallocates memory allocated with new.
16. Which feature allows multiple functions with the same name but different parameters?
- Function Overloading
- Function Overriding
- Inheritance
- Encapsulation
Answer: Function Overloading
Function overloading allows multiple functions with the same name but different parameter lists.
17. Which concept allows a derived class to provide a specific implementation of a base class function?
- Function Overriding
- Function Overloading
- Encapsulation
- Abstraction
Answer: Function Overriding
Function overriding allows a derived class to redefine a virtual function.
18. Which keyword is used to define a constant value in C++?
- const
- constant
- final
- static
Answer: const
The const keyword declares variables whose values cannot be changed.
19. Which Standard Template Library (STL) container stores elements in dynamic arrays?
- vector
- array
- stack
- queue
Answer: vector
std::vector is a dynamic array provided by the C++ STL.
20. Which of the following is a major advantage of C++?
- Object-Oriented Programming
- High Performance
- Memory Management
- All of the above
Answer: All of the above
C++ provides OOP features, high performance, and direct memory management.