Possible Duplicate:
Undefined Behavior and Sequence Points
#include <iostream>
using namespace std;
int main()
{
int x[3] = {};
int i=0;
x[i] = i++;
cout << x[0] << " " << x[1] << endl;
return 0;
}
Codepad is giving me this: Line 9: warning: operation on 'i' may be undefined Why is the operation undefined?
Clearly explained here: C-Faq
Why doesn't this code:
a[i] = i++;
work?Relevant Standard Quotation is as follows:
C++03 5 Expressions [expr]:
Para 4:
You are modifying a variable and using its value without an intervening sequence point. What do you expect is the value of
i
whenx[i]
appears? Because whatever you expect, you'd be wrong to expect that.