Comments in C or any other programming language is very important. It is never ever helpful for any user but they play a very important role if other programmers wish to understand your programming code.
There are two types of comment syntax in C language. You can use any one of them but as per usages.
Type of Comments in C
There are two types of comments in C language.
- Single line comment
- Multiline comment
Single line comments in C
If you want to use a comment that it is only a single line. So you can use single-line comment syntax.
//single line comment
#include<stdio.h> #include<conio.h> void main() { int a,b; //variable declaraction clrscr(); //clear the screen printf("Hello World");//print the statement "Hello World" getch();//display output screen until you press any key }
You can see above code, all statements have single-line comments. You can use comments in your programming code. Commenting in your program code is a good habit. It helps other programmers to understand your code.
Multiline Comments in C
If you want to write a few lines as a comment to understand other programmers about your program code. You can use multiline comments in C.
/*multiline comments that are easy to use in C*/
#include<stdio.h> #include<conio.h> /*This program is a simple program that is used to display a simple message hello world in console*/ void main() { int a,b; clrscr(); printf("Hello World"); getch(); }
In the above code, you can see an example of a multiline comment in C. Basically, it is used to brief the program concepts, variable initialization, and role of a function.
You can also read
- A Simple C Program: Let’s Understand C Programming
- Escape Sequences in C Programming [Complete List]
- Syntax of variable declaration in C
Hope that you understand the commenting in C. Please ask your questions in below comment section. Also, don’t forget to share this post in your social family.