In this post, we will read about comments and understand what is the use of comments in C programming and how we can use comments in our code.
Apart from this, we will also see the syntax of types of comments and their practical example. Let us first understand what is the need of comments.
When we learn programming, our program code, which we also call source code, is very small, that is, it does not contain many statements (lines of code).
But when we make programs in real life, there are thousands of lines of code in them and in this code we or any other programmer also have to make some changes in future.
Now the problem comes in this that after looking at the code after a long time, some things (lines of code) are not understood or should I say that it takes time to understand.
Apart from this, it may also happen that if another programmer makes changes to your source code, it will take him a lot of time to understand your code.
To avoid this problem in C Programming, we use description text notes in the middle of our source code, which we call comments.
Because of the comments, programmers remember this or should I say that it is easy to understand that for what purpose he wrote some specific lines of code or what was the logic of these lines of code.
This increases the readability of your source code and using comments is also considered a good programming practice.
Comments are used for programmers and not for compilers, that is, for C compiler, comments are non-executable statements.
Therefore the compiler ignores the comments while compiling your source code and the comments are not visible in the output of your program.
In C Programming, 2 types of comments are used, whose syntax and examples are given below.
You can also read: Main Function in C Programming
Single Line Comment:
Multi Line Comment
In a single line comment, the double forward slash symbol // is used at the beginning of the comment.
In multi line comment, /* at the beginning of the comment and */ forward slash and asterisk symbol is used at the end.
Single Line Comment Example Program:
Multi Line Comment Example Program:
Output: The output of both the programs will be same.
Value of i : 20
I hope that you have liked this post. If you liked the post, then please share it with your friends and relatives and you can send your suggestion in the comment box below or email me at email@example.com.