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 variables and it what way is it different from constants?
Write a program to print factorial of given number without using recursion?
How many keywords (reserve words) are in c?
In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?
What is pointers in c?
What is structure and union in c?
Is malloc memset faster than calloc?
PLS U SENS ME INTERVIEW O. MY EMAIL ADD, SOFIYA.SINGH@GMAIL.COM
What is scope rule in c?
What is a macro in c preprocessor?
what is diffrence between linear and binary search in array respect to operators?what kind of operator can be used in both seach methods?
What does dm mean sexually?
What is the use of static variable in c?
What is the difference between typedef and #define?
Explain zero based addressing.