二维数组额地址问题学习,本文学习内容参考:http://blog.csdn.net/wwdlk/article/details/6322439
#include<iostream> using namespace std; int main() { int A[3][3]; //声明一个二维数组 memset(A, 0, sizeof(int) * 9); //给二维数组赋初值0 for (int i = 0;i < 3;i++) { for (int j = 0;j < 3;j++) A[i][j] = i * 3 + j; } //验证A[i]的值和*(A+i)的值 for (int i = 0;i < 3;i++) { cout << "A[" << i << "]=" << A[i] << " "; cout << "*(A+"<< i << ")="<< *(A + i) << " "; cout << "A+" << i << "=" << A + i << " "; cout << endl; } cout << "------------------分割线------------------" << endl; //打印数组元素值和地址 for (int i = 0; i < 3; i++) { cout << "A[" << i << "]=" << A[i] << " "; cout << "*(A+" << i << ")=" << *(A + i) << " "; cout << "A+" << i << "=" << A + i << " "; cout << endl; for (int j = 0;j < 3;j++) { cout << "A[" << i << "][" << j << "]'s value is :" << A[i][j] << endl; cout << "the address is :" << *(A + i) + j << endl; } cout << endl; } system("pause"); return 0; }
result:
总结:
由以上的运行结果可以看出,表示二维数组的每一行的初始地址有三种方式:A[i] A+i *(A+i)
表示二维数组的每个元素的地址的方式有 : *(A+i)+j &A[i][j]
需要注意的是:这里的*(A+i) 并不是表示的元素的值,而是表示地址