Detailed Explanation of Comments in C Language

Comments in C language are used to provide information about lines of code and are widely used for code documentation. There are two types of comments in C language.
  • Single-line Comments
  • Multi-line Comments

Single-line Comments

They are indicated by double slashes (//). Let’s look at an example of a single-line comment in C language.
#include<stdio.h>int main(){// Print information
printf("Hello C");return 0;}
Output:
Hello C
You can even add comments after statements. For example:
printf("Hello C");// Print information

👇 Click to receive👇

👉 C Language Knowledge Resource Collection

Multi-line Comments

Multi-line comments are indicated by slash and asterisk (/* … */). They can span multiple lines of code but cannot be nested. The syntax is as follows:
/* Code to be commented */
Let’s look at an example of a multi-line comment in C language.
#include<stdio.h>int main(){/* Print information multi-line comment */
printf("Hello C");return 0;}
Output:
Hello C
Programmer Technical Exchange Group

Scan the code to join, remember to note: city, nickname, and technical direction.



Leave a Comment