C Single Line Comment

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Single Line Comment

Comments are non-executable code used to provide documentation to programmer. Single Line Comment is used to  comment out just Single Line in the Code. It is used to provide One Liner Description of line.

Some Importatnt Points :

  1. Single Line Comment Can be Placed Anywhere
  2. Single Line Comment Starts with ‘//’
  3. Any Symbols written after ‘//’ are ignored by Compiler
  4. Comment cannot hide statements written before ‘//’ and On the Successive new line

Live Example :

#include<stdio.h>
void main()
{
printf("Hello"); //Single Line Comment
printf("By");
}

Which Part is Ignored by Compiler ? [Shown by Asterisk]

#include<stdio.h>
void main()
{
printf("Hello"); // ********** Until Line Ends *****
printf("By");
}

Explanation :

  1. In the above code we have included Single Line Comment. Single Line Comment can be used anywhere in the code.
  2. Single Line Comment ignores the complete line from the position where it has been written.Therefor Single line comment is written usually after termination of statement.
  3. For Multiple Line Comment we have another approach.Learn More on Difference between Single Line and Multiple Line Comment.

Different Ways of Writing Singular Line Comment :

For Specifying Operation

#include<stdio.h>
int main()
{
int cvar=1,dvar=2;  // Declare Variables
int sum = 0;        // Declare Sum
sum = cvar + dvar;  // Compute Sum
printf("Sum : %d",sum);
return(0);
}

We can use this type of comment to specify the operation that we are performing or to specify the formula used.