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
Tell me is null always defined as 0(zero)?
what are the advantages of a macro over a function?
can any one tel me wt is the question pattern for NIC exam
Write a code of a general series where the next element is the sum of last k terms.
What's the right way to use errno?
What does %c mean in c?
What is data type long in c?
How many keywords (reserve words) are in c?
GIven a sequence of characters. How will you convert the lower case characters to upper case characters. ( Try using bit vector - sol given in the C lib -> typec.h)
What is difference between structure and union with example?
Can you mix old-style and new-style function syntax?
What is the difference between malloc calloc and realloc in c?
Explain the process of converting a Tree into a Binary Tree.
What does *p++ do?
What are the various types of control structures in programming?