Comments in C Language
November 5, 2009 by Zohaib Ahmed Shakir
Comments are generally those lines of code which the compiler or you can say computer skips and has no effect on our program.It is used to make our source code more readable i.e easy to understand.
There are two types of comments
1) Single line comment
2) Multiple line comment
I will now describe how we can use single line comment in our c language program
Code in C Language
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
//We are calculating Force of an object
b=5; //b represents mass of an object
c=15; //c represents acceleration of an object
a=b*c; //a represents force of the object and is calculated by the //formula F=ma
printf(“%d”,a);
getch();
}
Here you see double backslash ‘// ‘ is used for single line comments.The statement written after it will be skipped by the computer and has no effect on our final code, but using single line comment means that the statement which you want to write in comments should be in same line in which double backslash is placed.i.e
//aaaa
is not same as
//aaa
a
Now iam showing the procedure for multiple line comments
Code in C language
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
/*We are calculating Force of an object */
b=5; /* b represents mass of an object */
c=15; /* c represents acceleration of an object *
a=b*c; /* a represents force of the object and is calculated by the formula F=ma */
printf(“%d”,a);
getch();
}
Here we are using backslash with a starik * symbol i.e /* and */
/* represents the starting point of multiple comment whereas */ represents ending point of multiple comment .We can use it in multiple lines beacause it has a starting and ending point.
/* Saad
Asad
Farooq
*/
The above mentioned three names are commented and compiler skips all the lines written in between those multiple comment symbols.It is best to use multiple comment rather than single comment because if i accidently press a return key enter key it will have no effect in multiple comment whereas it is an error in single comment.
Advertisement
Like this:
Be the first to like this post.
Comments in C Language
November 5, 2009 by Zohaib Ahmed Shakir
Comments are generally those lines of code which the compiler or you can say computer skips and has no effect on our program.It is used to make our source code more readable i.e easy to understand.
There are two types of comments
1) Single line comment
2) Multiple line comment
I will now describe how we can use single line comment in our c language program
Code in C Language
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
//We are calculating Force of an object
b=5; //b represents mass of an object
c=15; //c represents acceleration of an object
a=b*c; //a represents force of the object and is calculated by the //formula F=ma
printf(“%d”,a);
getch();
}
Here you see double backslash ‘// ‘ is used for single line comments.The statement written after it will be skipped by the computer and has no effect on our final code, but using single line comment means that the statement which you want to write in comments should be in same line in which double backslash is placed.i.e
//aaaa
is not same as
//aaa
a
Now iam showing the procedure for multiple line comments
Code in C language
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
/*We are calculating Force of an object */
b=5; /* b represents mass of an object */
c=15; /* c represents acceleration of an object *
a=b*c; /* a represents force of the object and is calculated by the formula F=ma */
printf(“%d”,a);
getch();
}
Here we are using backslash with a starik * symbol i.e /* and */
/* represents the starting point of multiple comment whereas */ represents ending point of multiple comment .We can use it in multiple lines beacause it has a starting and ending point.
/* Saad
Asad
Farooq
*/
The above mentioned three names are commented and compiler skips all the lines written in between those multiple comment symbols.It is best to use multiple comment rather than single comment because if i accidently press a return key enter key it will have no effect in multiple comment whereas it is an error in single comment.
Like this:
Posted in C Language | Tagged Multiple Line comments c language, Single Line comments c language | Leave a Comment
Comments RSS