今天写题的时候想到一个想法,就比如访问a[1]
元素能不能用1[a]
表示呢?
写了一下:
#include<bits/stdc++.h>
#define debug(x) cout<<#x<<'='<<x<<'\n';
using namespace std;
int a[2]={
-1,1};
int main(){
cout<<1[a];
return 0;
}
结果编译成功了。
???
这个是指针和数组编译时的概念。
编译的时候,系统会把一个数组元素进行解析,就比如:
a[9]
就是首先把他拆成数组a
和下标9
,然后访问数组a
拥有的空间的9
号空间,所以说a[9]
还又一个写法:*(a+9)
所以说这段code
#include<bits/stdc++.h>