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


Please Help Members By Posting Answers For Below Questions

Tell me is null always defined as 0(zero)?

664


what are the advantages of a macro over a function?

633


can any one tel me wt is the question pattern for NIC exam

1551


Write a code of a general series where the next element is the sum of last k terms.

581


What's the right way to use errno?

611






What does %c mean in c?

639


What is data type long in c?

617


How many keywords (reserve words) are in c?

603


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)

676


What is difference between structure and union with example?

586


Can you mix old-style and new-style function syntax?

654


What is the difference between malloc calloc and realloc in c?

641


Explain the process of converting a Tree into a Binary Tree.

2094


What does *p++ do?

576


What are the various types of control structures in programming?

620