(Detailed) array of pointers and pointer arrays

Foreword

A recent C language problem, review the way a wave
priority first operators clear:
namely: ()> []> *

text

Pointer array: array of pointers, i.e., pointers to memory array, i.e. the array elements are pointers
array pointer: a pointer to an array, i.e., a pointer to an array

int *p1[10];\\指针数组
int (*p2)[10];\\数组指针

"*" Higher "[]" priority ratio. p1 first with "[]", the definition of what constitutes an array, array named p1, int modification of the contents of the array, i.e., each element of the array. So, now we know that this is an array, which contains 10 data points to an int pointer, that pointer array. For better understanding p2, where "()" priority "[]" is higher than " " and the numbers p2 configuration definition of a pointer, the pointer variable named p2, int is modified contents of the array, i.e., each element of the array. Array here and no name, is an anonymous array. Now we know that p2 is a pointer to an array of 10 int data type containing, namely an array of pointers. We can help deepen understanding of the following diagram:
Here Insert Picture Description

The following describes in detail the array of pointers and pointer arrays

Pointer array

int a[3][4];
int *p[n];

[] * Higher priority than, first with p becomes an array, then this is understood by the int * pointer to an integer array, which has n pointer type of array elements. Note that the implementation of p + 1 is incorrect, similar to p = a, such an assignment is wrong; for p is agnostic representation, there is only p [0], p [1], p [2] ... p [n -1], respectively, and they can be used to store a pointer variable is a variable address. However, this can be a = * p; where * p indicates the first element of the pointer array (i.e. p [0], which is a pointer), a value of the first address.

\\将二维数组赋给一个指针数组:
int *p[3];
int a[3][4];
for(i=0;i<3;i++)
p[i]=a[i];

Here int * p [3] denotes a one-dimensional array of memory placed three indicator variables, which are p [0], p [1 ], p [2]
so be assigned respectively.

Array pointer (also known as row pointer)

int a[3][4];
int (*p)[n];

() Priority] is higher than [therefore be described first p is a pointer to a one-dimensional array of integers, the length of the one-dimensional array is n, p can be said step size. That is executed when p + 1, p to cross the data length n integers.

\\将二维数组赋给一个数组指针:
int a[3][4];
int (*p)[4]; //该语句是定义一个数组指针,指向含4个元素的一维数组。
 p=a;        //将该二维数组的首地址赋给p,也就是a[0]或&a[0][0]
 p++;       //该语句执行过后,也就是p=p+1;p跨过行a[0][]指向了行a[1][]

So, also known as array pointer points to a one-dimensional array of pointers, also known as the row pointer.

表示数组中i行j列一个元素:
*(p[i]+j)、*(*(p+i)+j)、(*(p+i))[j]、p[i][j]

Reference: https://www.cnblogs.com/hongcha717/archive/2010/10/24/1859780.html

postscript

Small holiday Games

Published 65 original articles · won praise 101 · views 90000 +

Guess you like

Origin blog.csdn.net/qq_40563761/article/details/102688674