SQL PHP HTML ASP JavaScript articles and free scripts to download
 

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;
}




Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Join Our Email List
Email:  
For Email Newsletters you can trust
Basic of C
C Sections