Skip to main content

C Comments

Comments in C language are used to provide description about lines of code. It is widely used for documenting code. At run-time, a comments are ignored by the compiler.

There are 2 types of comments in the C language.

  1. Single Line Comments
  2. Multi-Line Comments

Single Line Comments :

Single line comments are represented by double slash //. 

Let's see an example of a single line comment in C.

#include <stdio.h>

int main()
{
// to print text on console we use print function
printf("Hello World");

return 0;
}

Multi Line Comments:

Multi-Line comments are represented by slash asterisk /* ... */. It can occupy many lines of code, but it can't be nested.

Syntax:


/* Sample Multiline Comment
Line 1
Line 2
….
…
*/

Need Of comments?

As a good programmer who writes codes understood by a human is better than a programmer who generates codes understood only by the machine.

So, it is highly recommended to insert comments to your code because it is good programming practice. Comments do not affect a program because the compiler ignores them.

Comments help the developer understand the logic/algorithm of the code if he revisits it after a long time.

Comments