C++ Quiz: Test Your Knowledge

Challenge yourself with this C++ quiz to assess your understanding of the language. Whether you’re a beginner or an experienced programmer, these questions will help you evaluate your knowledge and improve your coding skills.

Beginner-Level Quiz

1. Basic Syntax

What is the correct syntax to output “Hello, World!” in C++?

  • A. print("Hello, World!");
  • B. cout << "Hello, World!";
  • C. System.out.println("Hello, World!");
  • D. printf("Hello, World!");

Answer:

2. Data Types

Which of the following is NOT a valid C++ data type?

  • A. int
  • B. string
  • C. char
  • D. float64

Answer:

3. Variables

What will be the output of the following code?

int a = 5, b = 10;
cout << a + b;
  • A. 5
  • B. 10
  • C. 15
  • D. None of the above

Answer:

4. Comments

Which of the following is used for single-line comments in C++?

  • A. /* comment */
  • B. // comment
  • C. <!-- comment -->
  • D. # comment

Answer:

5. Loops

What is the correct syntax for a for loop in C++?

  • A. for (int i = 0; i < 10; i++) { /* code */ }
  • B. for (int i = 0; i < 10) { /* code */ }
  • C. for i in range(0, 10): { /* code */ }
  • D. for (int i = 0; i++) { /* code */ }

Answer:

Intermediate-Level Quiz

6. Functions

Which keyword is used to return a value from a function in C++?

  • A. send
  • B. output
  • C. return
  • D. value

Answer:

7. Arrays

What will be the output of the following code?

int arr[] = {1, 2, 3, 4};
cout << arr[2];
  • A. 1
  • B. 2
  • C. 3
  • D. 4

Answer:

8. Pointers

What does the following code do?

int a = 10;
int *p = &a;
  • A. Declares a pointer p and assigns it the value 10.
  • B. Declares a pointer p that stores the address of a.
  • C. Declares a pointer p and initializes it to NULL.
  • D. None of the above.

Answer:

9. Object-Oriented Programming

Which of the following access specifiers makes members accessible only within the same class?

  • A. private
  • B. protected
  • C. public
  • D. static

Answer:

10. File Handling

Which header file is used for file handling in C++?

  • A. fstream
  • B. iostream
  • C. cstring
  • D. cstdio

Answer:

Advanced-Level Quiz

11. Polymorphism

Which concept allows a function to have multiple implementations?

  • A. Encapsulation
  • B. Inheritance
  • C. Polymorphism
  • D. Abstraction

Answer:

12. Templates

Which keyword is used to define templates in C++?

  • A. template
  • B. class
  • C. typename
  • D. struct

Answer:

13. Exceptions

Which of the following is used to handle exceptions in C++?

  • A. try-catch
  • B. if-else
  • C. switch-case
  • D. do-while

Answer:

14. STL (Standard Template Library)

Which STL container stores elements in a key-value pair?

  • A. vector
  • B. list
  • C. set
  • D. map

Answer:

15. Memory Management

Which operator is used to release dynamically allocated memory in C++?

  • A. delete
  • B. free
  • C. dispose
  • D. clear

Answer:

Take the Quiz at The Coding College

For more interactive C++ quizzes and exercises, visit The Coding College. Sharpen your programming skills and become a C++ expert. 🚀

Leave a Comment