Quiz Entry - updated: 2026.06.23
What are the two types of comments in C and what's the gotcha with multi-line comments?
Single-line // and multi-line /* … */ — and the gotcha is that /* */ comments don't nest, so the first */ ends the whole comment.
// Single-line comment (C99 onwards)
/* Multi-line
comment */
/* Nested comments DON'T work:
/* This breaks! */
The comment ended at the first */
*/
The nesting problem:
/* Comment out this code
x = 5; /* initialize x */
y = 10;
*/
// ERROR: Comment ended at first */, leaving "y = 10; */" as code!
Solutions for commenting out code:
- Use
//for each line - Use
#if 0 ... #endif(preprocessor trick)
#if 0
x = 5;
y = 10; /* This comment is fine now */
#endif