0

Possible Duplicate:
Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc…)

Consider, following 2 coding lines in C

int a=0;

printf("%d%d%d%d",++a,a+1,a++,++a);

in visual C++, it gives

output:3431

But in Turbo C++ gives:

output:3311

This is also compiler dependent?

Community
  • 1
  • 1
SHRI
  • 2,406
  • 6
  • 32
  • 48

1 Answers1

2

The C specification does not specify the order that the arguments to your function will be evaluated, so there's no guarantee what output you will get.

Gabe
  • 84,912
  • 12
  • 139
  • 238
  • 1
    It's not just that the output isn't guaranteed. He's modified `a` more than once between sequence points, which leads to undefined behavior. Therefore it's not just a matter of "could be 3 or 4", but could also include "formats the hard disk", "blows up the machine", or essentially anything else. – Jerry Coffin Feb 24 '12 at 17:28