-2

I wish to know that why this code shows different Output on different compilers. Here's the Code:-

int a = 5;
printf("%d %d",a++,++a);

Output:- 6 7 (Visual Studio)

Output:- 6 6 (CodeBlocks)

sepp2k
  • 363,768
  • 54
  • 674
  • 675
monsterspy
  • 43
  • 5

1 Answers1

3

This is undefined behavior and it depends on the compiler which you are using. And to add it has nothing to do with the order of precedence.

You may check Precedence and Order of Evaluation

Also from C99 standard:

The order of evaluation of the operands is unspecified. If an attempt is made to modify the result of an assignment operator or to access it after the next sequence point, the behavior is undefined.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331