* I think that GATE questions are generally being asked on the basis
of logic and not depend how intelligent our compiler is*. I never
experienced that any GATE question have been asked based other than the
logic.
       Sudhir, as you wrote that at first time in the third line, when
printf was used, it was declaration but i want to ask if it is a declaration
then where is the body of the function? and again if it is declaration then
when i used the declared function then it should work according to how it
was declared no matter that we have used a function that is already declared
in C library because function overloading is allowed. It didn't show any
warning or anything. I think as it appeared to me,this program has used the
library defined printf() function and if compiler can use printf() or
scanf() function without declaring prototype then it is out of our
convention that we use in our C program and so i think it is something other
than the intelligence of compiler.
       Haven't you ever experienced this type of problem or question? Please
tell me some fruitful solution and logic that i can use to solve other
question asked in GATE or in other respected exams.
Thanks
On Sat, Feb 6, 2010 at 4:52 PM, sudhir kumar <[email protected]> wrote:

> On Sat, Feb 6, 2010 at 4:29 PM, rakesh kumar <[email protected]> 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
> > [email protected]
> > http://frodo.hserus.net/mailman/listinfo/ilugd
> >
>
>
>
> --
> Sudhir Kumar
>
_______________________________________________
Ilugd mailing list
[email protected]
http://frodo.hserus.net/mailman/listinfo/ilugd

Reply via email to