假设有一数组,其声明和初始化情况如下:
int a[4]={1,2,3,4};
现欲访问该数组中下标值为2的元素,有如下办法:
(1)a[2]
(2)*(a+2)
现在我们专门研究第二种的变体:
a[2]=*(a+2)=*(2+a)=2[a]
[例程]
#include <iostream>
using namespace std;
int main(void) {
int a[4]={1,2,3,4};
cout<<a[2]<<endl;
cout<<*(a+2)<<endl;
cout<<*(2+a)<<endl;
cout<<2[a]<<endl;
return 0;
}