<分区>
通常我们以这种方式访问数组元素:arrayName[elementID]
。但即使我们像 elementID[arrayName]
这样使用它也会编译并且不会在运行时导致任何错误。逻辑上是不是错了?谁能给我解释一下。我是 C++ 的新手。提前感谢您的帮助!
#include<iostream>
using namespace std;
int main()
{
int arr[4] = {2, 4, 5, 7};
cout << arr[2] << endl; //this is the correct way to use it
cout << 2[arr] << endl; //this gives the same result and does not cause any errors
return 0;
}