DamnSchool
The comment statement is not executable. Comments are like helping text in C program and they are ignored by the compiler and it is very helpful to understand the program easily. There are two types of comment in C program.
  1. Single line comment
  2. Multi line comment

1.Single line comment.

  1. It can be Placed anywhere in C program.
  2. Single line comment starts with " // ".
  3. It can't be split over Multiple lines like Multi line comment.
  4. Any symbols written after "//" will be ignored by C compiler.
Example:

// Title   :  Learn C
#include <stdio.h> 
int main()
 {
  printf("Learn C :)");   // Single line comment 
  return 0;// Until the end of line will be ignored by C compiler 
 }

Run Example >

2. Multi line comment.

  1. It can be Placed anywhere in C program.
  2. Single line comment starts with "/*" and ends with "*/".
  3. It can be split over Multiple lines.
  4. It can be used like Single line comment.
Example:

/*
  Title     :  Learn C
  */
  #include <stdio.h> 
  int main()
  {
  printf("Learn C :)");   /* It can be used like Single line comment */
/*-----------------------------------------------------------------
  printf("Learn C program");   Ignored By C Compiler
 ------------------------------------------------------------------*/
  return 0; 
  }

Run Example >

Different way of using comments

We can use comment to specify variables and some operation like addition, subtraction, etc.., .


Example:

/*********************************
  *    Title     :  Learn C
  *********************************/
  #include <stdio.h> 
  int main()
  {
  int a=5,b=5;
  int c;       //   To display output
  c=a+b;   //  Addition 
/*
  c=a-b;   //  Subtraction 
  */
printf("Value of c=%d",c);
  return 0; 
  }
  
Run Example >


< Previous Next >

Privacy Policy Terms of Service About
Creative Commons License
This work is licensed under a Creative Commons Attribution-NoDerivatives 4.0 International License.