Comments In C Language | Single line comment and Multiline comment

In this series of C Language, Today we will learn in detail about what is comment in C language? And how to use comments in C language.

So lets learn about the Comments in C

Comments In C
Comments In C Language

What Is Comments In C

When we create a program in C language, then we comment on a line inside the program to describe or explain it well. Comment helps the programmer to explain the logic used in that line of the program. Commenting makes the code on that line easier to read and understand.

Comment is a statement that is not executed and run by the compiler. The compiler ignores the comment written inside the programs because the comment is only for the programmer.

When the program becomes too long or when the programmer re-works on that program after a long time, then the programmer can easily understand the logic used in that line by reading the comments written in that line. So basically this is the real purpose of commenting.

Types of Comments in C Language

There are two types of comments in C language -:

  1. Single line comment
  2. Multi-line comment

1. Single line comment

Single line comment is used in single line only. Single line comment is represented as double forward-slash (//).

Syntax -:

The syntax of single line comment is like this:

// Single line comment

Let us understand the single line comment by this example, this example is the same for both C and C ++ languages.

Example -:

// C program example
// Single Line comment
#include
int main (void)
{
printf ("Welcome to CsTutorialpoint"); // printing information
return 0; // return zero
}

You can run this program online here Online C Compiler.

Output -:

Welcome to CsTutorialpoint

2. Multi-line comment

Multi line comment starts with an asterisk slash (/) and ends with an asterisk slash (/). You can use multi line comments anywhere in your code. A multi-line comment can be one or more than one line in a program.

Syntax -:

The syntax of the multi-line comment is like this:

//* Comment starts

Line 1

Line 2

….

…

Comment ends 
* /

Example

Let us understand the multi-line comment by this example:

// C program example
// Multi Line comment
#include <stdio.h>
int main (void)
{

/*
With the main () function, we start writing programs.
Every program in C language has a main () function from where the program starts.
*/

printf ("Welcome to CsTutorialpoint"); // Here I Print some Information

return 0;
}

Output -:

Welcome to CsTutorialpoint

You can also comment at the end of the program, which will appear in the last line of the code.

Example -:

int age = 40; // age of the person (single line comment)
int age = 25; / * age of the person * / (Multi-line comment)

Read More -:

Conclusion

Friends, I hope that you have found the answer to your question and you will not have to search about the Comments in C Language

However, if you want any information related to this post or related to programming language, computer science, then comment below I will clear your all doubts 

If you want a complete tutorial of C language, then see here C Language Tutorial. Here you will get all the topics of C Programming Tutorial step by step.

Friends, if you liked this post, then definitely share this post with your friends so that they can get information about the Comments in C Language

To get Programming Language, Coding, C, C ++, related information, subscribe to our website newsletter. So that you will get information about our upcoming new posts soon.

Jeetu Sahu is A Web Developer | Computer Engineer | Passionate about Coding, Competitive Programming, and Blogging

Leave a Comment