手机
当前位置:查字典教程网 >编程开发 >C语言 >深入解析int(*p)[]和int(**p)[]
深入解析int(*p)[]和int(**p)[]
摘要:1.int(*p)[10]:根据运算符的结合律,()的优先级最高,所以p是一个指针,指向的一个维度为10的一维数组。p一个指向数组的某一行复...

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;

}

【深入解析int(*p)[]和int(**p)[]】相关文章:

深入分析C中不安全的sprintf与strcpy

深入解析C语言中typedef的四个用途

c++友元函数与友元类的深入解析

深入理解结构体中占位符的用法

深入解析C++中的构造函数和析构函数

C++ using namespace std 用法深入解析

深入解析C++ STL中的常用容器

C语言中的BYTE和char深入解析

深入解析C语言中常数的数据类型

深入分析Linux下如何对C语言进行编程

精品推荐
分类导航