1

Possible Duplicate:
Undefined Behavior and Sequence Points

after the following c++ code, the array a contains: 0, 1, 2, 3, 4

int a[5] = {0,1,2,3,4};
int i = 2;
a[i++] = a[i++];

i expected it to be: 0, 1, 3, 3, 4

could anyone explain me why?

Community
  • 1
  • 1
clamp
  • 31,604
  • 74
  • 198
  • 296

1 Answers1

8
 a[i++] = a[i++];

Because it is Undefined Behavior.

Good Read:
Sequence Points
Undefined Behavior and Sequence Points

Community
  • 1
  • 1
Alok Save
  • 196,531
  • 48
  • 417
  • 525