源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-05-20 15:46 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:深入解析int(*p)[]和int(**p)[]
[b]1. int(*p)[10]: [/b]根据运算符的结合律,()的优先级最高,所以p是一个指针,指向的一个维度为10的一维数组。 p一个指向数组的某一行
[u]复制代码[/u] 代码如下:
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)<<" ";     }
[b]2. int(**q)[10] [/b]这个的意义:q是一个指针,指向的元素就是1.中的p. [b]下面给一个例子: [/b]
[u]复制代码[/u] 代码如下:
#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; }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部