Comments In C Programming Language


In this video tutorial lets learn about using comments in C programming language.

There are 2 types of comments in C program

1. Single Line Comment.
2. Multi-line comment.

Why Do We Need To Use Comments In Source Code?

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!

Video Tutorial: Comments In C Programming Language


[youtube https://www.youtube.com/watch?v=fNu6hAVr6A0]

YouTube Link: https://www.youtube.com/watch?v=fNu6hAVr6A0 [Watch the Video In Full Screen.]

Source Code: Comments In C Programming Language

/*
 * 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

Leave a Reply

Your email address will not be published. Required fields are marked *