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
  • 33,000
  • 75
  • 203
  • 299

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
  • 202,538
  • 53
  • 430
  • 533