为什么X [Y] == Y [X]在C ++? [英] Why does x[y] == y[x] in c++?
本文介绍了为什么X [Y] == Y [X]在C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:结果
在C数组为什么这是真的吗?一个[5] == 5 [A]
有人告诉我这个...我不相信他们在第一,但它确实工作。如果x和y不整个code改变,为什么这项工作:
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;
}
如何点¯x数组的索引y值是= x索引的价值在列Y?但没有Ÿ阵列。
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]
因为int是内在的,有可交换的==操作符,这将永远是真实的。
since int is intrinsic and has commutative operator==, this will always be true
这篇关于为什么X [Y] == Y [X]在C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文