信息发布→ 登录 注册 退出

深入解析int(*p)[]和int(**p)[]

发布时间:2026-01-11

点击量:
1. int(*p)[10]:
根据运算符的结合律,()的优先级最高,所以p是一个指针,指向的一个维度为10的一维数组。
p一个指向数组的某一行
复制代码 代码如下:
int a[1][4]={1,2,3,4};
    int (*p)[4] = a;//p point to the row of array a
    for(int i=0;i<4;i++)
    {
     cout<<*((*p)+i)<<" ";
    }

2. int(**q)[10]
这个的意义:q是一个指针,指向的元素就是1.中的p.
下面给一个例子:
复制代码 代码如下:
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int a[2][2]={1,2,3,4};
    int (*p)[2] = a;//p point to the row of array a
    for(int i = 0;i<2;i++)//output matrix using p
    {
            for(int j = 0;j<2;j++)
            {
                    cout<<*(*(p+i)+j)<<" ";
            }
            cout<<endl;
    }
    int (**q)[2] = &p;//q point to p
    for(int i = 0;i<2;i++)//output matrix using q
    {
            for(int j = 0;j<2;j++)
            {
                    cout<<*(*(*q+i)+j)<<" ";
            }
            cout<<endl;
    }

    getchar();
    return 0;
}
标签:# BR  # return  # getchar  # output  # main  # endl  # matrix  # int  # FONT  # STRONG  # COLOR  # style  # int(*p)[]  # nbsp  # point  # row  # array  # span  # 结合律  # 运算符  # 是一个  # 深入const int *p与int * const p的区别详解(常量指针与指向常量的指针)  # int(**p)[]  
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!