Single Line Comment : C Programming
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 :
- Single Line Comment Can be Placed Anywhere
- Single Line Comment Starts with ‘//’
- Any Symbols written after ‘//’ are ignored by Compiler
- 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 :
- In the above code we have included Single Line Comment. Single Line Comment can be used anywhere in the code.
- 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.
- 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.