C - Comments what is the use of comments and how to write comments in c language.
In C-language we have two type of Comments one is Single line comments and second one is Multi Line comment.
Comments are non-executable code used to provide documentation to programmer. Single line comment out just single line in the code. It is used to provide One Liner Description of line.
#include < stdio.h >
void main()
{
printf("Hello"); //Single line comment
printf("Bye");
}
#include < stdio.h >
void main()
{
printf("Hello"); /* Multi line comment */
printf("Bye");
}
In C-language we have two type of Comments one is Single line comments and second one is Multi Line comment.
Single Line Comment
Comments are non-executable code used to provide documentation to programmer. Single line comment out just single line in the code. It is used to provide One Liner Description of line.
Important Points
- Sinle line comment placed in Any where
- Single line comment start with "//"
- Any symbols writeen afer"//" ignored by compiler
- Comment can not hide statements written before "//" and on the successive new line
Example
#include < stdio.h >
void main()
{
printf("Hello"); //Single line comment
printf("Bye");
}
Explanation
- In the above code we have included single line comment.Single line comment can be used in any where in the program
- Single line comment ignores the complete line form the position where it has been written. There for single line comment usually after ending of statement.
Multi Line Comment
- Multi line comment placed any where in program.
- Multi line comment start with /*.
- Multi line comment ends with */.
- Any symbols written between '/* and */' are ignored by compiler.
- It can split over mulitple lines.
Example
#include < stdio.h >
void main()
{
printf("Hello"); /* Multi line comment */
printf("Bye");
}
Rules of Writing Comments in C
- Program contain any number of comments at any place.
- Nested comments are not allowed. i.e Comment with in comment.
- Comments an be split over more than one line.
- Single comments starts with '//'.
Difference between Single line and multi line Comments
| Single line Comment | Multi line comment |
|---|---|
| Single line comment start with '//'. | Multi line comment start with */ and ends with */ |
| statements after the symbol // upto the end of line ignored. | All words and statements writing between /* and */ are ignored. |
| Comments ends whenever ENTER is pressed New line Starts. | Comments ends when */ occurs. |
| eg. // Single line comment | eg./* Multi line comment*/ |

No comments:
Post a Comment