C Comments

Comments are used to describe the code. These lines are not displayed in the website. It offers an option of leaving notes for yourself or others. The comment simplifies the production of more readable code. There are two types of C programming comments:

  • Single-line Comment
  • Multi-line Comment


Single-line Comment

A single-line comment is represented by //. It is used for commenting a single line.

Example

  1. #include <stdio.h>
  2. int main()
  3. {
  4. // This is a single line comment
  5. printf("Hello, World!");
  6. return 0;
  7. }

Output:

Hello, World!


Multi-line Comment

Multi-line comments open with /* and close with */.

Example

  1. #include <stdio.h>
  2. int main()
  3. {
  4. /* This is a
    multi-line comment */
  5. printf("Hello, World!");
  6. return 0;
  7. }

Output:

Hello, World!