C++ 数组的地址问题学随笔

二维数组额地址问题学习,本文学习内容参考: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:

图片 1

总结:

鉴于以上的运作结果好看来,表示二维数组的每一行的起来地址发生三栽办法:A[i]
   A+i    *(A+i)

             表示二维数组的每个元素的地址之办法有 :
 *(A+i)+j    &A[i][j]   

亟需注意的是:这里的*(A+i)
并无是意味着的素的值,而是意味着地址