Table of Contents
< All Topics

11. Comments in C Programming

Comments in the C language is used to provide information about lines of code. They are widely used for documenting code. There are two 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.


// use two forward slashes to create a single comment
// This is a single line comment in code, compiler will not compile this line

int main()

    // you can place single line comment anywhere in code, as per your need. Like-

    //printing information    
    printf("Welcome to EzyLearning");    // Even you can place comment just after the end of ;

return 0;  

Welcome to EzyLearning

Multi-Line comments

A comment that begins with /* and ends with */ can be placed anywhere in your code, on the same line or multiple lines. This feature is useful for adding explanatory notes or temporarily disabling certain parts of the code for testing purposes. Just be mindful not to overuse comments, as they can clutter the code and make it harder to read.

/* Sample Multiline Comment
statement-Line 1
statement-Line 2
statement-Line 3
statement-Line 4
statement-Line 5

#include <stdio.h>
int main() 
/* in main function
one can write any dscription about the problem, code or a statement.
This comment can be of single or multiple lines.

programmer can also this paird character set /*.....*/ to hide a certain set of multi-line-statements 
or block of code  

int i = 7; //x is a integer variable
printf("%d", i);
return 0;

Multi-line comments are mostly useful while you are debugging a large set of code, or you want to describe certain set of statements.

Leave a comment