二维指针数组、数组指针的用法

1.废话不多说,先上代码:

#include <iostream>
using namespace std;

int main(void)
{    
    int v[2][5] = {{1,2,3,4,5},{6,7,8,9,10}};
    int (*a)[5] = v;        //指针数组,指针指向数组 a[5],a[5]里面是int数值 该指针等于v的地址 
    
    cout<<(*a+1)<<endl;        //*a是v[0][0]的地址。  0x22fe04
    cout<<(*a+2)<<endl;        //输出0x22fe08
    cout<<*(*a+2)<<endl;    //a[0][1]的值 3 
    cout<<*(a+1)<<endl;        //输出 v[1][0]的地址。 0x22fe14
    cout<<**(a+1)<<endl;    //a[1][1] = 6 
    
    int b[3]={11,12,13};
    cout<<"一维数组:"<<endl;
    cout<<b<<endl;            //b[0]的地址0x22fe30
    cout<<(b+1)<<endl;        //b[1]的地址 0x22fe34
    cout<<(&b+1)<<endl;        //输出指向b的指针的地址+sizeof(b[3])的地址:0x22fe3c
    cout<<*(b+1)<<endl;        // 12
    cout<<*(&b+1)<<endl;    //输出的是0x22fe3c ,输出的是他的地址值   (只能记住先!!)


    cin.get();
    return 0;
}

2.指针数组和数组指针的区别:

指针数组 : int (*p)[3];  //指针指向数组,p是一个指向数组p[3]的指针。

数组指针:  int p[3];    //数组内存到数据是指针

----------跟 指针常量  常量在指针有点类似,谁先执行谁先读,然后根据读的方向判断具体意思。

原文地址:https://www.cnblogs.com/simonLiang/p/5985736.html