Saturday, December 16, 2006

A simple c program :-

# include stdio

# include conio

void main()

{

printf("5");

}

Do you beleive this simple C program covers almost 10% of c.

Now three qution arises :-

1. what is conio.h and stdio.h ?

2. what is void main() and why we are using it ?

3. what is printf option?

To get the answers of these three qution we will perform some tricks :-

1. We remove (# include conio.h ) from the program. Now after removing conio.h we observe that program is still running and not showing any error.Therefore qution arises that why are we using it? yes in this program we does'nt require it but we are playing a secure game, in simple words i wanna say that it is used in many programs so why take risk! And don't worry i will explain it complete in next chapters.

We remove ( # include stdio.h ) opps this time program is showing error =>undefined function printf. It clearly tells us that stdio is related to printf statement and it is used to define printf. So by doing this we get our second answer.

2. Now, i wanna tell you that we are using void main because our compiler use it as a main gate of the program.We usually think that program start from #include files ....NO i waanna tell you that this is misconception. Compiler always search main function in the program and if it does'nt find it program becomes unexecutable.

3. Now you are thinking that what is the use of printf function. I just wanna tell you that you will understand it better if use you will use different things in printf for eg in my program i am using 5 in printf you can use any statement at the place of 5.

look here =>

printf("i am hero"); or printf("i am hero heralal no.1"); or printf("i proud to be indian"); anything you want.....and i want you to play with it. As much as you will play as much you will enjoy. But remmember the format (" "); now please don'nt ask why?

No comments: