C++ Quiz: Program Structure, Syntax & Tokens

Q1. What is the purpose of the #include <iostream> directive in a C++ program?

A) To create a function
B) To include input/output functionalities
C) To define a variable
D) To compile the program

Q2. Which of the following is a valid single-line comment in C++?

A) It runs the main program
B) It allows input/output operations
C) It defines class names
D) It controls code formatting

Q3. What is the purpose of a header file like <iostream> in C++?

A) It runs the main program
B) It allows input/output operations
C) It defines class names
D) It controls code formatting

Q4. What will happen if you forget to add a semicolon (;) at the end of a C++ statement?

A) Nothing
B) It will show a compile-time error
C) It will crash the system
D) It will remove the line automatically

Q5. Identify the correct multi-line comment syntax in C++:

A) // Comment starts here and ends after some lines //
B) /* This is a comment that spans multiple lines */
C) # This is a comment block
D) — Multi-line comment —

Q6. Which of the following symbols is used to define a code block in C++?

A) ()
B) []
C) {}
D) <>

Q7. Why is indentation important in C++ even though it is not enforced by the compiler?

A) It increases memory usage
B) It is required for output
C) It improves code readability and structure
D) It changes the execution flow

Q8. Choose the correctly formatted single-line comment:

A) -- Comment here
B) # Comment here
C) // Comment here
D) /* Comment here */

Q9. What type of token is the word return in this line?

return 0;

A) Identifier
B) Constant
C) Symbol
D) Keyword

Q10. Which of the following is true about braces {} in C++?

A) Used to end a function only
B) Required only for if-else
C) Define the beginning and end of code blocks
D) Not required in modern


ANSWER KEY

1. B
2. C
3. C
4. B
5. B
6. C
7. C
8. C
9. D
10. C

    Leave a Reply

    Your email address will not be published. Required fields are marked *