Comments in C Programming

Comments in C Programming post thumbnail image

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:

Comments in C Programming
Comments in C Programming

Multi Line Comment

Comments in C Programming
Comments in C Programming

Explanation:

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:

Comments in C Programming
Comments in C Programming

Multi Line Comment Example Program:

Comments in C Programming
Comments in C Programming

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 praveen171086@gmail.com.

You can also visit my Hindi YouTube Channel.

mm
Avinash Singh

I am Avinash Singh, a software engineer from the profession and have been working in the IT industry since 2009. I live in Barabanki district of Uttar Pradesh in India and completed intermediate in 2001 from Ram Sevak Inter College, a UP Board school. After inter I completed my professional degree (BCA & MCA) from Indira Gandhi National Open University, Delhi in 2008 and along with it I did many certifications to keep my knowledge up to date and the next year I started a software development company E – Vision Technocraft Pvt Ltd.

Leave a Reply

Your email address will not be published.

Related Post