In this video tutorial lets learn about using comments in C programming language.
Page Contents
1. Single Line Comment.
2. Multi-line comment.
1. Whenever someone looks at the code, they need not spend much time in understanding the logic and what that code snippet does. Instead they can simply read the comment and understand the purpose of the code snippet.
2. If there is comment at the top of program, anybody can read it and understand the purpose of the program itself. Usually developers display author information, title and the date of writing the program.
3. When there are multiple contributes to the source code, it’s best to have comments to credit the code contributor and also it’ll be helpful for the other contributes to look at the comment and understand the purpose of the code immediately, instead of tracking the logic and understanding it.
4. If we look at our own code after some time, comments will surely help us understand why we wrote the code in the first place!
/* * Author: SATISH * Link: Technotip.com * Language: C Programming * Title: Comments In C * Multi-author: No */#include<stdio.h> #define PI 3.14 // Value of PI int main() { float r = 5.0; // Logic to calculate area of circle printf("Area of Circle is %f\n", (PI * r *r )); /* We could go further and add more features to this program in future. */ return 0; }
Output:
Area of Circle is 78.500000
Single Line Comment
Whatever is written after double forward slash ( // ) in that same line, will be treated as comment.
Multi-Line Comment
Anything written inside a /* and */ is considered multiple comment. Text inside /* and */ can be written in multiple lines and all those things will be considered as comments.
Note: Comments are not executed as part of the program. Comments are not even compiled. They’re present only for the user to read and understand the purpose of the code.
For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List
For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert