QUIZ 60

What is the output of the following code ?

int i = 7;
printf(“%d %d %d”, i++,i, ++i);

a. 9 9 9
b. 7 8 9
c. 8 8 8
d. either b or c

Answer : (d)

When printf is called evaluation of expression is done first, and then sent as parameter to printf.
It is compiler dependent , the way in which evaluation is done and variable are pushed onto stack, it may be from right to left or left to right.
The compiler which push variables onto stack from left to right, the values printed are 7 8 9 and in case of right to left, the answer is 8 8 8

Leave a Reply

Your email address will not be published. Required fields are marked *