Challenger App

No.1 PSC Learning App

1M+ Downloads
Which of the following is not a correct C++ comment ?

A/*comment*/

B/*comment*\\

C//'comment*/

D/*//comment/*/

Answer:

B. /*comment*\\

Read Explanation:

C++ Comment Syntax Overview

  • Single-line comments: Represented by //. Any text following this marker on the same line is ignored by the compiler.
  • Multi-line (Block) comments: Represented by /* ... */. Everything placed between these delimiters is treated as a comment, allowing for documentation that spans multiple lines or portions of a line.

Key Rules and Constraints

  1. Nested Comments: C++ does not support nested block comments. Attempting to wrap a block comment within another (e.g., /* /* ... */ */) will result in a compilation error because the compiler interprets the first */ as the end of the entire comment block.
  2. Invalid Syntax: Using syntax markers incorrectly, such as mixing styles or omitting delimiters, leads to syntax errors. For example, using // to start a multi-line block without repeating the marker on each line or attempting to use invalid characters within the comment markers is prohibited.
  3. Compiler Behavior: Comments are treated as white space by the C++ preprocessor and are completely removed before the compilation process begins.
  4. Best Practices: While // is widely used for brief descriptions, /* */ is often preferred for temporarily commenting out large segments of code during debugging.

Related Questions:

Which of the following is a computer code ?
ഒരു ഹൈപ്പർ ലിങ്ക് സൃഷ്ടിക്കാൻ ഉപയോഗിക്കുന്ന HTML Tag ഏതാണ്?
In programming, what is the purpose of a loop?
Which computer language is used for Artificial Intelligence among the following?
Find the user defined data type in C :