Single Line Comments
Single line comments span over one line only and are ignored by the compiler.
In C they can be done with a double Slash.
In this case we do NOT need a semicolon at the end of the line.
They can either be above a part of the code...
Example:
#include <stdio.h>
int main()
{
// This is a single line comment
printf("%s", "Hello, World!");
return 0;
}
Or they can be in the same line of the code...
Example:
#include <stdio.h>
int main()
{
printf("%s", "Hello, World!"); // This is a single line comment
return 0;
}
Multi Line Comments
Multi line comments span over two or more lines and are ignored by the compiler.
In C they start with a slash and an asterisk and end with an asterisk and a slash.
In this case we do NOT need a semicolon at the end of the line.
Example:
#include <stdio.h>
int main()
{
/*
This is
a multi
line comment
*/
printf("%s", "Hello, World!");
return 0;
}
Single Line comments and Multi Line Comments can also be used together.
Example:
#include <stdio.h>
int main()
{
/*
This is
a multi
line comment
*/
printf("%s", "Hello, World!"); // And this is a single line comment
return 0;
}