Tutorials

C Tutorial

All Tutorials Learning Tools Login

C Tutorial · Chapter 5 of 16

C Comments

Explain code without changing program behavior.

Use // for a single-line comment and /* ... */ for multi-line comments.

Good comments explain why, not just what the code already shows.

Comments sample Try it Yourself »
#include <stdio.h>

int main(void) {
    // Greet the student
    printf("Hello\n");
    /* End of program */
    return 0;
}

Classroom Tips

  • Do not leave old broken code commented forever.
  • Comment the purpose of tricky logic.