darpangoel:
> can anyone explain how printf works. is it's output implementation dependent?
The page explains it best:
http://computer.howstuffwo
It has a section that covers printf exclusively...
> and also kindly explain the output for the following code.
imladris already covered it, so I'm not going to repeat it... :)
Hope That Helps,
Dex*
Main Topics
Browse All Topics





by: imladrisPosted on 2003-11-14 at 11:02:20ID: 9750163
I'm not sure about your question about "output implementation dependant". However, the output is readily explainable.
In C, arguments are pushed onto the stack right to left. That is the rightmost argument goes onto the stack first, then the one next to it, etc. and the first argument is pushed last. This means that the called function finds the first argument at the "stack frame" (the spot the stack will be popped to when it needs to return).
So, since i is 10, the first value pushed onto the stack will be 11 (10, preincremented), the second will be 12 (preincremented again), then 12 again, then the format specifier. And so it will print exactly what you saw: 12 12 11.