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