C | Functions | Question 11

Output of following program?

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


(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

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up
Article Tags :
Practice Tags :


1


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