Comment makes the program easier to understand.
Let's see what we use comment for with a small example.
I am writing a program. I am giving that program to my friend. My friend wants to add some more features. But he is not able to understand my program because I have not given any explanation about the program I have written. There is only one solution for this problem. That is the comments. Using these comments, we can tell why we wrote this program and how it will work.
There are two types of comments.
1. Single line comment
2. Multi line comment
Single line comment:
It is started with double forward slash(//). It will not take any sentence we give after double forward slash as a program.
If you run this program, the compiler will not take this sentence.
#include<stdio.h>
int main()
{
printf(“Hello World”); //Display the hello world.
return 0;
}
Multi Line Comment:
It starts with Forward Slash(/*) and ends with star Forward(*/).
Ex:
Who wrote this program and in which language he wrote it and why he wrote this program will be given through a multiline comment. In this case the compiler will not find it and will ignore it.
When using this type of comment, someone else can easily understand and read my program.
/*
Program Name : Print the Hello World
Using Language: C
Developer Name: xyz
*/
#include<stdio.h>
int main()
{
printf(“Hello World”);
return 0;
}