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

Output is 4 4 on gcc. Please explain this output

user2492165
  • 93
  • 1
  • 6

1 Answers1

2

This is undefined behaviour. The order of evaluation of the function parameters is not defined by the C standard.

Relevant sections: C99 Section 6.5.2.2 Paragraph 10

The order of evaluation of the function designator, the actual arguments, and subexpressions within the actual arguments is unspecified, but there is a sequence point before the actual call.

also in C99 Section 6.5.2.2 Paragraph 10

There is a sequence point after the evaluations of the function designator and the actual arguments but before the actual call. Every evaluation in the calling function (including other function calls) that is not otherwise specifically sequenced before or after the execution of the body of the called function is indeterminately sequenced with respect to the execution of the called function.94)

phoxis
  • 60,131
  • 14
  • 81
  • 117