Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Please explain the output for the program below: (The postfix operator is evaluated first for all the outputs)

0 votes
asked May 15 by Niraja Lakka (120 points)

int main()
    int a=4;
   //printf("%d %d %d", a++, a, ++a );   Output: 5 6 6  
  // printf("%d %d %d", ++a, a, a++ ); // Output:  6 6 4
    //printf("%d %d %d", ++a, a++, a ); // Output:   6 4 6
    return 0;

2 Answers

0 votes
answered 2 days ago by akash gupta (140 points)
output=4 5 6

7 7 7

 7 8 8
0 votes
answered 2 days ago by Peter Minarik (34,450 points)
edited 2 days ago by Peter Minarik

This has been asked before (I cannot find the previous question though...)

TL;DR; This question does not have a single solution. It depends on the compiler.

Please, read this (external) thread.

The problem here is that the C standard does not specify in what order the arguments should be processed for a function call. Similarly, in the linked thread, the problem is that the C standard does not specify for the addition operator whether the left or the right side should be evaluated first.

Just try various compilers and (e.g. GNU C, Microsoft C, Turbo C, etc) and you'll see how the result changes.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.