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?
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?
a[i++] = a[i++];
Because it is Undefined Behavior.
Good Read:
Sequence Points
Undefined Behavior and Sequence Points