the difference between an array pointer and an array of pointers
Click to open the link
Array pointer (also called row pointer)
define INT (*p) [n];
() A high priority, first of all, that P is a pointer to a one-dimensional array of integers, the length of the one-dimensional array is n, which can be said to be the step of P. That is to say, when the p+1 is executed, p crosses the length of n integer data.
To assign a two-dimensional array to a pointer, you should assign a value like this:
int a[3][4];
int (*p) [4]; The statement defines an array pointer that points to a one-dimensional array of 4 elements.
P=a; Assigns the first address of the two-dimensional array to p, i.e. a[0] or &a[0][0]
p++; After the statement is executed, that is, P=p+1;p crosses the line a[0][] points to the row a[1][]
So the array pointer also refers to a pointer to a one-dimensional array, also called a row pointer.
Array of pointers
define int *p[n];
[] high priority, combined with p to an array, and then int* that this is an integer pointer array that has an array element of n pointer types. It is wrong to perform p+1 here: P=a because P is an agnostic representation, only p[0], p[1, p[2]...p[n-1], and they are pointer variables that can be used to hold variable addresses. But can be so *p=a; Here *p represents the value of the first element of the pointer array, the value of the first address of a.
To assign a two-dimensional array to an array of pointers:
int *p[3];
int a[3][4];
for (i=0;i<3;i++)
P[i]=a[i];
Here int *p[3] represents a one-dimensional array containing three pointer variables, respectively p[0], p[1], p[2]
So you want to assign values separately.
So the difference between the two is suddenly clear, the array pointer is just a pointer variable, it seems that the C language is specifically used to point to a two-dimensional array, it occupies the memory of a pointer to the storage space. An array of pointers is a number of pointer variables that exist as an array in memory and occupy multiple pointers in storage space. The
also needs to be explained that when used to point to a two-dimensional array, the reference is the same as the array name reference.
For example, to represent an element in the I row J column of an array:
* (P[I]+J), * (* (p+i) +j), (* (P+i)) [j], P[i][j]