Why does x[y] == y[x] in c++?
Possible Duplicate:
In C arrays why is this true? a[5] == 5[a]
Someone told me this... I didn't believe them at first but it does work. If x and y do not change throughout the code, why does this work:
int x [5] = { 0,1,2,3,4};
int y = 3;
if(x[y] == y[x]){
cout << "Why..." << endl;
}
How does x array's value in index y is = the x index's value's in array y? But there was no y array.
It is always true (for normal operator==)
a[i] --> *(a+i) --> *(i+a) --> i[a]
since int is intrinsic and has commutative operator==, this will always be true
因为以下所有内容都是相同的:
x[y] == y[x] == *(x+y) == *(y+x)
因为x[y]
只是说*(x + y)
另一种方式,并且与*(y + x)
。
上一篇: 使用printf语句的不寻常输出