VOOZH about

URL: https://www.geeksforgeeks.org/c/c-comments/

⇱ C Comments - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C Comments

Last Updated : 18 Oct, 2025

The comments in C are human-readable notes in the source code of a C program used to make the program easier to read and understand. They are not executed by the compiler or an interpreter.


Output
Hello

Single-line Comments

Single-line comments are used to comment out a single line of code or a part of it. The single line comments in C start with two forward slashes (//), and everything after the slashes on that line is considered a comment. They are also called C++ Style comments as they were first introduced in C++ and later adopted in C also.


Output
Value of x: 5

In this C program, the comments provide explanations about the code. The compiler ignores the comments and does not execute them.

We can also create a comment that displays at the end of a line of code using a single-line comment. But generally, it's better to practice putting the comment before the line of code.


Output
Hi

Multi-line Comments

Multi-line comments in C are used write comments that span more than one line. They are generally used for longer descriptions or for commenting out multiple lines of code. In C language, these comments begin with /* and end with */. Everything between these markers is treated as a comment.


Output
Welcome to GeeksforGeeks

Nesting Comments in C

In C language, comments cannot be nested. That means you cannot place a multi-line comment inside another multi-line comment in C language. If you try to do so, the compiler will treat the closing */ of the inner comment as the end of the entire multi-line comment. and the rest of the part after the inner closing (*/) will not be commented.


Output

./Solution.c: In function 'main':
./Solution.c:6:8: error: unknown type name 'This'
This line will cause an error because the compiler
^
./Solution.c:6:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'will'
This line will cause an error because the compiler
^

If nested comments are needed, it’s best to use single-line comments or comment out individual parts.


Output
Program runs without errors.

Best Practices for Writing Comments in C

Following are some best practices to write comments in your C program:

  • Write comments that explain a complex logic in simple language.
  • Do not comment on every line unnecessarily and avoid writing obvious comments.
Comment
Article Tags:
Article Tags: