Tuesday, February 22, 2011

A common misconception...

Today i am going to dicuss about a misconception about function in the minds of beginners....
The common misconcption is to assume that the function of following prototype does not take any argument...
void check();
which is totally wrong ,instead the above prototype states that the function check can take any number of arguments....
-->Using the keyword void withing the braces is the correct way to tell the compiler that the function takes NO arguments.....
void check(void);

lets take an example.....
void check();
void main()
void check(int a,int b)
printf("We are on the right way now");

The above program will compile for sure,and the output will be.
We are on the right way now

Now we can see this is compiling and running because we have declared function check to take any number of arguments.....
if we call check by saying check(10,20);  the output will be:
We are on the right way now
 And  we can call check by saying check(10,20,30,40,50,60,70) that is with any number of arguments...

Now change the prototype with void check(void);...now you can't use the above stuff.......