Nearby lessons

7 of 72

C - 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.

In simple words: a comment is a sticky note on your code. It costs nothing to run, but it saves hours when you (or someone else) reads the code later.
Example01
Loading editor…

Single-Line Comments (//)

Everything from // to the end of that line is a comment. Use it for one-line notes.

In simple words: // comments out the rest of the line — and only that line. The next line is code again.
Example02
Loading editor…

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.

Example03
Loading editor…

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.
Quick Check: does // printf("hi"); print anything? No — the whole line is a comment, so the compiler never sees the printf at all.
📝 Key Takeaways
  • 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

🧠 Test Your Knowledge

5 Questions
Progress: 0 / 5

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.