Which of the following is a single-line comment in C++?
A
# This is a comment B
/* This is a comment */ C
// This is a comment D
<!-- This is a comment -->
Analysis & Theory
// is used for single-line comments in C++.
Which syntax is used for multi-line comments in C++?
A
// comment // B
/* comment */ C
# comment D
-- comment --
Analysis & Theory
/* ... */ is used for multi-line comments in C++.
What will happen if you forget to close a multi-line comment in C++?
A
It will throw a warning. B
It will be ignored. C
It will cause a compilation error. D
It will auto-correct.
Analysis & Theory
Unclosed multi-line comments cause a compilation error because the compiler can't parse the rest of the code.
Which of the following is NOT a valid comment in C++?
A
// This is valid B
/* This is valid */ C
# This is invalid D
//This is also valid
Analysis & Theory
# is not used for comments in C++. It's used in preprocessor directives, not general comments.
Why are comments used in programming?
A
To speed up code execution B
To make code shorter C
To document and explain code D
To confuse others
Analysis & Theory
Comments are used to explain code, making it more understandable for humans.
Can comments be used inside a function in C++?
A
No, only outside functions B
Yes, anywhere in the code C
Only before the main() function D
Only after return statements
Analysis & Theory
Comments can be placed anywhere in C++ code, including inside functions.
Which of the following will be ignored by the C++ compiler?
A
int x = 10; B
// int x = 10; C
/* int x = 10; */ D
Both 2 and 3
Analysis & Theory
Any code within // or /* */ is ignored by the compiler.
Can you nest comments in C++ (i.e., comment inside another comment)?
A
Yes, with // only B
Yes, with /* */ C
No, C++ does not support nested comments D
Only in C++20
Analysis & Theory
C++ does not support nested comments. For example, /* ... /* ... */ ... */ causes errors.
Which of these is most useful for temporary code disabling in C++?
A
Deleting the code B
Using cout to print the code C
Commenting it out D
Renaming variables
Analysis & Theory
Commenting out code allows you to temporarily disable it without deleting it.
What is the main difference between // and /* */ comments?
A
// is slower than /* */ B
// is for code, /* */ is for output C
// is for one line, /* */ can span multiple lines D
There is no difference
Analysis & Theory
// is used for single-line comments; /* */ can span multiple lines.