Page 80 - C-Language
P. 80
These /* type of comments can be used on their own line, at the end of a code line, or even within
lines of code:
/* this comment is on its own line */
if (x && y) { /*this comment is at the end of a line */
if ((complexCondition1) /* this comment is within a line of code */
&& (complexCondition2)) {
/* this comment is within an if, on its own line */
}
}
Comments cannot be nested. This is because any subsequent /* will be ignored (as part of the
comment) and the first */ reached will be treated as ending the comment. The comment in the
following example will not work:
/* outer comment, means this is ignored => /* attempted inner comment */ <= ends the comment,
not this one => */
To comment blocks of code that contain comments of this type, that would otherwise be nested,
see the Commenting using the preprocessor example below
// delimited comments
C99
C99 introduced the use of C++-style single-line comments. This type of comment starts with two
forward slashes and runs to the end of a line:
// this is a comment
This type of comment does not allow multi-line comments, though it is possible to make a
comment block by adding several single line comments one after the other:
// each of these lines are a single-line comment
// note how each must start with
// the double forward-slash
This type of comment may be used on its own line or at the end of a code line. However, because
they run to the end of the line, they may not be used within a code line
// this comment is on its own line
if (x && y) { // this comment is at the end of a line
// this comment is within an if, on its own line
}
Commenting using the preprocessor
Large chunks of code can also be "commented out" using the preprocessor directives #if 0 and
#endif. This is useful when the code contains multi-line comments that otherwise would not nest.
https://riptutorial.com/ 56

