C | Functions | Question 11

Output of following program?

#include <stdio.h>
int main()
    int i = 5;
    printf("%d %d %d", i++, i++, i++);
    return 0;

(A) 7 6 5
(B) 5 6 7
(C) 7 7 7
(D) Compiler Dependent

Answer: (D)

Explanation: When parameters are passed to a function, the value of every parameter is evaluated before being passed to the function.

What is the order of evaluation of parameters – left-to-right or right-to-left?
If evaluation order is left-to-right, then output should be 5 6 7 and if the evaluation order is right-to-left, then output should be 7 6 5. Unfortunately, there is no fixed order defined by C standard. A compiler may choose to evaluate either from left-to-right.

So the output is compiler dependent.

Quiz of this Question

My Personal Notes arrow_drop_up

Practice Tags :
Article Tags :
Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.

Recommended Posts:

2 Average Difficulty : 2/5.0
Based on 2 vote(s)

User Actions