--- In [email protected], Gopi Krishna Komanduri <[EMAIL PROTECTED]> wrote: > > Hi , > I want to know 3 things. <snip> > 4) main() > { > printf("%d"); > }; > In the above , the output I am getting is garbage. But what I am thinking is as printf is a function and %d is one parameter and no other parameters , it will push only %d onto stack . so when it starts executing , it will pop only %d and it won't get any other value from stack to resolve that %d. So May I know how compiler is giving some garbage , with out stops printing? > >
Perhaps you have read some wrong information about what happens with this code. This is a typical interview question in India, and the interviewers wrongly believe that it gives the value from stack, and they expect the same answer from the candidates. It is a very wrong belief. The C standard doesn't say anything about stack, so C implementations need not necessarily have 'stack'. When you do not give sufficient arguments to the format string in printf, the behaviour is undefined, that means it might give just about any result. Read: http://prokutfaq.byethost15.com/InsufficientFormatStringArguments
