Thursday 19 May 2011

Comments or How to comment a line?

It's helpful to be able to put comments into the source code file that can be read by humans but are invisible to the compiler. Here's an example:






/*this code calculates age in days*/
void main()
{
float years,days;      /*initialize variables*/
clrscr();   /*clear screen when you run the program second time*/
printf("Please type your age in years: ");   /*print prompt*/
scanf("%f",&years);               /*get age in years from user*/
days=years*365;
printf("\nYou are %.1f days old.\n",days);   /*print result*/
}


A comment begins with the two-character symbol slash-asterisk(/*) and ends with an asterisk-slash(*/). You can also use double slash(//) to comment a single line. Let's have a look at following example:


/*This is
a multi
line comment*/


//This is a single line comment




If you have any question, ask me freely...

0 comments:

Post a Comment