Nearby lessons
7 of 72C - Comments
Comments are notes you leave inside your source code for people to read — the compiler skips them completely. C gives you two styles: // for a single line and /* ... */ for a block. This lesson covers both, what comments are good for, and the one rule beginners always trip over: block comments cannot be nested.
What are Comments?
A comment is a note you write inside your source code to explain what the code does. Comments are written for people (including your future self) — the compiler skips them completely while building the program.
Single-Line Comments (//)
Everything from // to the end of that line is a comment. Use it for one-line notes.
// comments out the rest of the line — and only that line. The next line is code again.
Multi-Line Comments (/* */)
To write a note that spans several lines, open with /* and close with */. Everything in between is ignored by the compiler. This is the usual way to write a header block at the top of a file.
What Comments Can Do
- Explain tricky logic — a one-line note can save hours of reading.
- Document programs — header comments for author, date, purpose.
- Temporarily disable code — commenting a line stops it from running without deleting it.
// printf("hi"); print anything? No — the whole line is a comment, so the compiler never sees the printf at all.
- Comments explain code but are ignored by the compiler
- // marks a single-line comment
- /* ... */ marks a multi-line comment
- Comments never affect the output of a program
- Block comments do not nest — the first */ closes the comment