What is the output of the following statements?
int i = 0;
printf("%d %d", i, i++);
int i = 0;
printf("%d %d", i, i++);
A. 0 1
B. 1 0
C. 0 0
D. 1 1
E. None of these
Answer: Option B
Solution(By Examveda Team)
Since the evaluation is from right to left.So when the print statement execute value of i = 0
Since its execute from right to left when i++ will be execute first and print value 0 (since its post increment ) and after printing 0 value of i become 1.
So it its prints for 1 for next i.
Join The Discussion
Comments ( 11 )
Related Questions on Operators and Expressions
What does the ++ operator do in C when applied to a variable?
A. Decrements by 1
B. Adds 1
C. Doubles the value
D. Leaves it unchanged
int i = 5;
printf("%d %d", --i, i++)
it will print 0 na first
okay you have used stack property but how is 0 increemented before the completion of the statement?
but parenthesis associativity is left to right.
Umang! explanation already clear enough to understand. please read it and understand it. and run the above code to be sure about the answer.
if it prints 0 before 1 then ans should be A... how can u say B? Please Explain!!!
how?? is it wrong?
Answer updated. Please review for better clarification.
how??
i cant understand clearly...
please explain with each step...
I THINK IT MAY BE 1,1 IF EVALUATION FROM RIGHT TO LEFT