On Sat, Feb 6, 2010 at 4:29 PM, rakesh kumar <kumar3...@gmail.com> wrote:
> Hi all,
>         Today while studying a book i just saw the following lines of code:
> int main(void)
> {
>  int printf(const char *n,...);
This is pretty obvious and is declaration of a local function.
>  int a=1;
>  printf("abcdef");
This call willl result in the call to above defined local printf() function.
> return 0;
> }
>
>  and the output was: abcdef
> When i tried to run this code, it ran well without any error and this was
> asked in GATE exam also. I am confused, how it ran without <stdio.h>, when i
> used printf() function and gave the same output as printf gives. Okay after
> that i commented the third line "int printf(const char *n,....);", the
I think this is because of the improved intelligence in today's
compilers. However the
compiler warns you about the declaration of the function, but during
linkage time since
it links the program to the standard c library and hence the printf()
function from there
is called.

> output didn't get affected. Now i am thinking when we can use printf()
> function without any prototype or defining any header, then why do we need
> to use #include<> in our program, because when i changed this program a bit
One scenario I can think of is portability, other may be conflct which
may arise because
of a similar declaration of the function somewhere else in the code.

> by substituting printf() with scanf() it worked fine like scanf() does
> normally.
>  Can anyone explain me,what is this?
> Thanks
> _______________________________________________
> Ilugd mailing list
> Ilugd@lists.linux-delhi.org
> http://frodo.hserus.net/mailman/listinfo/ilugd
>



-- 
Sudhir Kumar

_______________________________________________
Ilugd mailing list
Ilugd@lists.linux-delhi.org
http://frodo.hserus.net/mailman/listinfo/ilugd

Reply via email to