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

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++?

  1. Dennis Ritchie
  2. Bjarne Stroustrup
  3. James Gosling
  4. Guido van Rossum

Answer: Bjarne Stroustrup

C++ was developed by Bjarne Stroustrup in 1979.

2. C++ is an extension of which programming language?

  1. C
  2. Java
  3. Python
  4. 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?

  1. .cpp
  2. .java
  3. .py
  4. .js

Answer: .cpp

The .cpp extension is commonly used for C++ source files.

4. Which function is the entry point of every C++ program?

  1. main()
  2. start()
  3. run()
  4. begin()

Answer: main()

Every C++ program begins execution from the main() function.

5. Which symbol is used to end a statement in C++?

  1. .
  2. :
  3. ;
  4. ,

Answer: ;

Every C++ statement ends with a semicolon.

6. Which keyword is used to define a class in C++?

  1. class
  2. Class
  3. struct
  4. object

Answer: class

The class keyword is used to define a class.

7. Which operator is used to access members of an object?

  1. .
  2. ->
  3. ::
  4. #

Answer: .

The dot operator accesses members of an object.

8. Which header file is required for cout and cin?

  1. <iostream>
  2. <stdio.h>
  3. <string>
  4. <math.h>

Answer: <iostream>

The iostream header provides cin and cout.

9. Which object is used to display output in C++?

  1. cout
  2. cin
  3. print
  4. echo

Answer: cout

cout is used to display output to the console.

10. Which object is used to receive input from the keyboard?

  1. cin
  2. cout
  3. input
  4. scanf

Answer: cin

cin is used to receive input from the user.

11. Which keyword is used for inheritance in C++?

  1. extends
  2. inherits
  3. :
  4. 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?

  1. public
  2. private
  3. protected
  4. friend

Answer: public

Public members can be accessed from outside the class.

13. Which access specifier allows access only within the class?

  1. private
  2. public
  3. protected
  4. default

Answer: private

Private members are accessible only inside the class.

14. Which keyword is used to create an object dynamically?

  1. new
  2. malloc
  3. create
  4. dynamic

Answer: new

The new keyword allocates memory dynamically for objects.

15. Which keyword releases dynamically allocated memory?

  1. delete
  2. free
  3. remove
  4. destroy

Answer: delete

The delete keyword deallocates memory allocated with new.

16. Which feature allows multiple functions with the same name but different parameters?

  1. Function Overloading
  2. Function Overriding
  3. Inheritance
  4. 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?

  1. Function Overriding
  2. Function Overloading
  3. Encapsulation
  4. 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++?

  1. const
  2. constant
  3. final
  4. 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?

  1. vector
  2. array
  3. stack
  4. 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++?

  1. Object-Oriented Programming
  2. High Performance
  3. Memory Management
  4. All of the above

Answer: All of the above

C++ provides OOP features, high performance, and direct memory management.

Take the timed quiz