C Comments

Beginner
6 min read
Updated: Nov 2026
1 example

What Is Comments?

Comments are notes for humans that the compiler ignores. Use /* ... */ for block comments (any C version) and // for single-line comments (C99 and later).

Remember
/* block comment:
   can span many lines */
// single-line comment (C99+)
int x = 5;   // trailing comment

Cheat Sheet

Keep these facts handy while you work with Comments in C.

TopicDetail
Block/* text */ cannot be nested
Line// text runs to end of line
Disable codeWrap code in #if 0 ... #endif
Good commentsExplain why, not what

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Keywords and Identifiers.

Example 1 — Documenting a calculation

A comment explains the reason for a formula; commented-out code does nothing.

C
#include <stdio.h>

int main(void) {
    double celsius = 25.0;
    /* Convert using F = C * 9/5 + 32 */
    double f = celsius * 9.0 / 5.0 + 32.0;
    // printf("debug: %f\n", celsius);   <- ignored
    printf("%.1f C = %.1f F\n", celsius, f);
    return 0;
}

How It Works

  1. The block comment documents the formula.
  2. The commented printf line is skipped entirely.
  3. Only the final printf produces output.

Edge Cases & Pitfalls

Check these before relying on Comments in real programs.

nest

Nested block comments

/* a /* b */ c */ ends at the first */, leaving c */ as code. Use #if 0 to disable large regions.

stale

Outdated comments

A wrong comment is worse than none. Update comments when code changes.

Key Takeaways

  • Block: /* */ works everywhere.
  • Line: // needs C99 or later.
  • Purpose: explain intent, not syntax.

One line: Comments are notes for humans that the compiler ignores.

Frequently Asked Questions

No. The preprocessor removes comments before compilation, so they cost nothing at run time.
Block comments cannot be nested. Use #if 0 and #endif to disable code that already contains comments.
Continue with "C Keywords and Identifiers" next. Reserved words versus the names you choose for variables and functions. The C Fundamentals hub lists every topic in order.

Next: Keywords and Identifiers

Reserved words versus the names you choose for variables and functions.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful