The code:
---------------------------------------------------------------
/* This is the previous addition program(program 3 of this blog) but in this I have also shown that how to place comments in a C program */ #includemain() { int i,j,k; printf("The program to add two numbers.\n"); printf("Enter first number.\n"); scanf("%d",&i); //taking variable i as input from user printf("Enter second number.\n"); scanf("%d",&j); //taking variable i as input from user k=i+j; printf("Sum = %d\n",k); }
---------------------------------------------------------------
Up to this point you have already noticed that there are 2 ways of putting a 'comment' in a C program. First type is a "single line comment"(see the fifth line inside main() ). This type of comment starts with '//'(2 slashes) and continues till the next line starts. The second type of comment is a "multi-line comment". As the name indicates it can have multiple lines. This 'comment' starts with '/*' and ends with '*/' and every thing between these '/*' and '*/' is considered as 'comment'.
Now some of you might be thinking what is a 'comment'? what is the role of a 'comment' in a C program? Am I right? Let me explain. A 'comment' does not affect the output of the program as it is not read by the 'compiler' (I am assuming that all of you know what a compiler is.) while it is compiling your 'source code'( 'source code' is the C program written by you). It is put in the program for humans. I mean if at a later time you or anyone else study your 'source code' then comments put by you will help him in understanding the program easily. A 'comment' can be put anywhere in the C program. In the following posts I'll be explaining things with the help of 'comments'.
No comments:
Post a Comment
feel free to ask your doubts... if any
you can post your doubts on
www.facebook.com/programsimply