Comments in C program

We can write comments in our code for easy understanding and future maintenance of the script. Writing comments are good habit. Statements written after // are treated as comments and ignored by C complier
int num ; // This part is comment
In the above statement we have declared num as a integer variable and then written a comment after //

Multiline comments

IN the above code we have seen how to write comments in each line. What is written after // is treated as comment and not executed by compiler. The next line is treated as code again. To make a bulk of statements including more than one line we have to use /* (starting of comment ) and then */ ( ending of comment portion )
/*
These are comments 
This is part of comment and will be ignored by C compiler 
Comments */
So once we use /* to start comment , then all statements written till end of comments marked by */ is ignored by compiler.
Nested comments are not allowed. So this line will generate error.
/*     comments /* some more */ again some more */  
In the above line the portion after */ will not be taken as comments so it will create problem. Here are some examples of writing comments .
#include <stdio.h>:
int main(void){
float num; // declaring a float variable
/* We can assign value to our variable like this */
num=17.873;
	printf("num = %5.3f", num);
	/* this is a part of plus2net
	c tutorial basic section
	you can learn more advance features here
	*/
return 0;
}
Your Rating




Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer