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
What are the types of operators in c?
difference between native and cross compilers
Which control loop is recommended if you have to execute set of statements for fixed number of times?
What is size of union in c?
Why is %d used in c?
Is null always defined as 0(zero)?
When can a far pointer be used?
What does static variable mean in c?
What are the types of assignment statements?
What is a macro, and explain how do you use it?
What is pivot in c?
Is it possible to use curly brackets ({}) to enclose single line code in c program?
Is there a way to switch on strings?
Explain 'bus error'?
Which programming language is best for getting job 2020?