Comments in C Language

Comments in the C language are used to provide extra details about various aspects of a program. They are usually included at the start of a program to indicate its purpose, its author, and the date on which it was written. They also provide clarification about complicated statements in the program.

Before moving further, we’ve prepared a video tutorial to understand what comments are in C:

Video: Comments in C Programming

Video: Comments in C Programming (Hindi)

There are two types of comments used in C. These are single-line comments and multi-line comments. Details about these are given as follows:

Single Line Comments

These comments are only on a single line and cannot move beyond that. They are represented using a double slash (//). An example of single-line comments in C is:

// Program to display single line comments
// Studyopedia - Never Stop Learning

#include < stdio.h >

   int main(void) {

      int a = 5;

      printf("Comments in C - Studyopedia\n");
      printf("\n----------------------------\n");

      printf("Hello\n");               // Printing Hello on screen
      printf("Value of a is %d", a);   // Printing value of a 

      return 0;
   }

The output of the above program is:

Comments in C

Multi-Line Comments

These comments can be extended over multiple lines. They are represented using /* i.e slash asterisk (/*……….*/). Multi-line comments cannot be nested. An example of multi-line comments in C is:

/* Program to display multi-line comments
   Studyopedia - Never Stop Learning */

#include < stdio.h >

   int main(void) {

      int a = 10;

      printf("Comments in C - Studyopedia\n");
      printf("\n-------------------------\n");
      printf("Hello\n");
      printf("Value of a is %d", a);

      return 0;
   }

The output of this program is:

Comments in C Language

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others:


For Videos, Join Our YouTube Channel: Join Now


Read More:

Loops in C Programming
Arrays in C Programming
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment