liveBook · Manning

Comment

As explained in Modern C, Third Edition

A comment is source text that the C compiler ignores and that can document a program.

A comment is source text that the C compiler ignores. Use comments to document code and improve its readability and comprehensibility without affecting program execution. section 2.1

C provides two comment forms:

  • A block comment begins with /* and ends with */; its contents may span several lines. section 2.1
  • A C++-style comment begins with // and continues to the end of its logical line. section 2.1
  • Prefer comments that explain purpose, context, or non-obvious implementation details; avoid restating obvious syntax or adding irrelevant decoration. section 10.0

Useful implementation comments

u = nextApprox(u, i, 33, 28); /* Theorem 3 ensures that we may move to the next step. */ ++i; section 10.0

 /* The main thing that this program does. */                                       

Inspect a compact block-comment example showing how comments can state a program's main purpose. section 2.1

How Modern C, Third Edition covers it

How deep it goes
Defines block and line delimiters and develops criteria for useful documentation, without descending into compiler internals.
Examples
Uses block comments, end-of-line comments, and a theorem-based rationale for advancing an approximation step.
What it assumes
Assumes familiarity with basic C source code and introduces comment syntax and documentation priorities.
What you can do after
Apply block and line comment syntax to document purpose and non-obvious implementation choices.
How it connects
Connects comments with compiler behavior, code readability, function interfaces, and implementation details.

Also explained in

Compare how 10 books explain comment →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.