liveBook · Manning

Comment

As explained in Modern C

A comment is source text in a C program that the compiler ignores as non-executable documentation.

```c /* The main thing that this program does. */ int main(void) { return 0; } ``` A comment is source text that the C compiler ignores as non-executable documentation. It can explain what code does, why it does it, or how an implementation is organized. section 2.1 section 10.0

C provides two comment forms and assigns documentation different jobs:

  • Block comments use `/* ... */`; everything between the delimiters is treated as a comment, even when it spans lines. section 2.1
  • C++-style comments begin with `//` and continue to the end of the line. section 2.1
  • Interface comments document a function's purpose; implementation comments explain the manner in which its details work. section 10.0

A comment can preserve the reason behind an operation

```c /* 33 and 28 are suitable because they are coprime. */ u = nextApprox(u, i, 33, 28); /* Theorem 3 ensures that we may move to the next step. */ ++i; ``` The executable statements remain visible, while the comments record assumptions and rationale that improve readability and comprehensibility. section 10.0

1   /* 33 and 28 are suitable because they are coprime. */
2   u = nextApprox(u, i, 33, 28);
3   /* Theorem 3 ensures that we may move to the next step. */
4   ++i;


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":1}],[{\"line\":0,\"ch\":14},{\"line\":0,\"ch\":15}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":1}],[{\"line\":0,\"ch\":7},{\"line\":0,\"ch\":8}],[{\"line\":1,\"ch\":25},{\"line\":1,\"ch\":26}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":1}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":1}]]"}
!@%STYLE%@!

Inspect the worked listing to compare explanatory block comments with the code they accompany. section 10.0

How Modern C covers it

How deep it goes
Defines block and line forms and distinguishes interface from implementation documentation, without detailing compiler internals.
Examples
Uses block comments explaining a program's purpose and implementation comments recording coprimality and a theorem-based step.
What it assumes
Assumes basic C source structure and punctuation while defining comment forms through concrete examples.
What you can do after
Apply C comment syntax to document purpose, interface behavior, implementation rationale, and coding assumptions.
How it connects
Connects documentation with function interfaces, implementation, header files, translation units, and code readability.

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. The section links point to the parts of the book it draws on.