取引用&的时候,把它后面的标识符视为一个变量,尤其是对于一个数组的时候(无论是几维的),&后加上数组的标识符就是表示取这个数组的首地址,注意:对于一维数组&A就是取数组首地址,对于二维数组&A[0]还是取数组第一行的首地址;对于三维数组&A[0]就是取第一个二维数组的首地址,&A[0][0]就是取第一个第三维数组的首地址,因为对于二维和三维数组而言,A[0]和A[0][0]都还是另外一个数组的首地址(也可以看作是另外一个数组的标识符)。
解引用*的时候,后面跟的是一个指针,特别对于一个数组而言时如果是数组的标识符,则是视为指针来处理的,解引用的结果就是得到了这个指针所指向的那块地址空间中所包含的内容。
测试代码如下:
void main(){
int ia1[2] = {1,2};
int *pInt = ia1;
cout << ia1 << endl;
cout << &ia1 << endl;
cout << *ia1 << endl;
cout << &ia1 << endl;
cout << "---------------------------------------"<< endl;
int ia2[2][2] = {{1,2},{3,4}};
int (*pA)[2] = ia2;
cout << &(*pA) <<endl;
cout << ia2 << endl;
cout << *ia2 << endl;
cout << *(ia2+1) << endl;
cout << ia2[1] << endl;
cout << &ia2 <<endl;
cout << ia2[0] <<endl;
cout << *ia2[0] << endl;
cout << &ia2[0] <<endl;
cout << &ia2[0][0] << endl;
cout << "---------------------------------------"<< endl;
int ia3[1][1][1] = {{{1}}};
int (*pB)[1][1] = ia3;
cout << ia3 << endl ;
cout << *ia3 << endl;
cout << &ia3 << endl;
cout << ia3[0] << endl;
cout << *ia3[0] << endl;
cout << &ia3[0] << endl;
cout << ia3[0][0] << endl;
cout << *ia3[0][0] << endl;
cout << &ia3[0][0] << endl;
}
其实理解上跟上次写的那个二维数组的指针运用的日志是一样的。