Comments in C

Comments are used to give additional useful information inside a C Program. Comments are optional and are just used to increase the readability of the program. Comments in the source code are ignored by the compiler.

There are 2 types of comments in the C language.

  1. Single Line Comments
  2. Multi-Line Comments

Single Line Comments

Single line comments are represented by double slash //. Let's see an example of a single line comment in C.

Syntax
Prefix "//" before the text which needs to be commented
//
snippet
#include  
int main(){  
	//printing information  
	printf("Hello C");  
return 0;
}
Output
Hello C

Even you can place the comment after the statement. For example:

snippet
printf("Hello C");//printing information

Mult Line Comments

Multi-Line comments are represented by slash asterisk \* ... *\. It can occupy many lines of code, but it can't be nested.

Syntax
/* 
code
to be commented
*/

Let's see an example of a multi-Line comment in C.

snippet
#include  
int main(){  
	/*printing information  
	  Multi-Line Comment*/
	printf("Hello C");  
return 0;
}
Output
Hello C
Note
We cannot have comments within comments, that is comments cannot be nested.
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +