CComments

Comments

Comments are text in your source file that the compiler completely ignores — they exist purely for the humans reading the code, and that includes your future self. C supports two comment styles.

Multi-line comments: /* */

Anything between /* and */ is a comment, no matter how many lines it spans:

C
/*
 * This function computes the average of an array of doubles.
 * Returns 0.0 if the array is empty.
 */
double average(double *values, int count) {
    if (count == 0) return 0.0;
    /* accumulate first, then divide once at the end */
    double sum = 0.0;
    for (int i = 0; i < count; i++) {
        sum += values[i];
    }
    return sum / count;
}
Block comments cannot nest
Putting a `/* */` comment inside another `/* */` comment does not do what you might expect. The first `*/` the compiler encounters closes the *outer* comment, leaving the rest as live code:

C
/* outer comment
   /* inner comment */
   this line is NOT a comment anymore, and will likely cause an error
*/

The safest way to temporarily disable a block of code that already contains /* */ comments is #if 0 ... #endif, which the preprocessor handles differently and doesn't have this nesting problem.

Single-line comments: //

Everything from // to the end of the line is a comment:

C
int total = 0;   // running total across all iterations
total += 5;      // add the current item's contribution
Standards compatibility
`//` comments were officially added to the C standard in **C99**. Code written strictly for **C89** (also called ANSI C) technically should not use them, since some older, strictly conforming compilers will reject them. In practice, virtually every modern compiler accepts `//` regardless of the standard you specify, but if you ever need to target a genuinely ancient toolchain, stick to `/* */`.
When to write comments

Good comments explain why, not what. The code itself already shows what it does; a comment restating that adds noise without adding information. Comments earn their keep when they explain a non-obvious reason, a tricky edge case, or an assumption that isn't visible just from reading the code.

Bad — restates the obvious

C
i++; // increment i by 1

Good — explains a non-obvious reason

C
i++; // skip the header row before reading data