void main()
{
int a=1;
printf("%d %d %d",a,++a,a++);
}
the output is supposed to be 1 2 2....but it is 3 3 1
this is due to calling conventions of C. if anyone can
explain me how it happens?
Answer Posted / sumant
In C the parameters are pushed on the stack from right to
left. So
1> it will push a=1 on the stack and do a++ making a=2
2> it will porform ++a making a = 3 and push value 3
3> it will push a on the stack which is 3
so the stack will have values 1 3 3 and it will POP in
the reverse order and thus printf will display 3 3 1
| Is This Answer Correct ? | 52 Yes | 11 No |
Post New Answer View All Answers
explain what is an endless loop?
why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???
hi to every one .. how to view table pool after creating the pooled table? plz help me.. if any knows abt this ..
What are the storage classes in C?
What the different types of arrays in c?
explain how do you use macro?
What is extern variable in c with example?
How can I invoke another program or command and trap its output?
What is ponter?
What are structures and unions? State differencves between them.
What is the scope of global variable in c?
How do you construct an increment statement or decrement statement in C?
What is the purpose of ftell?
Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?
What are the different types of errors?