The array name represents the first address of the array , for example ：
int a[10]; int *p=NULL; p=a;
among , Array name a Represents the first address of the array （ Namely &a[0]）, Then the expression a+i Represents that the subscript in the array is i element a[i] Address of , Namely &a[i].
You can also use indirect addressing * To reference array elements . for example ：*（a+i） Indicates that the first address element is removed, and then the i Contents of elements , The subscript is i Elements of a[i].
in addition , You can also use the pointer variable of one-dimensional array p To reference an array a Elements in ,*（p+i） It means take out p+i Refers to the contents of the memory unit , The element a[i] Value of .*（p+i）
It can also be used in the form of the following table p[i] To express .

for example ：
# include <stdio.h> int main(void) { int a[] = {1, 2, 3, 4, 5}; int *p, *q,
*r; p = &a[3]; // The first way to write printf("*p = %d\n", *p); q = a; // The second way of writing q = q + 3;
printf("*q = %d\n", *q); r = a; // The third way to write printf("*(r+3) = %d\n", *(r+3)); return
0; }
The output is ：
*p = 4
*q = 4
*(r+3) = 4
be careful ：（1） And adoption *（a+i） To reference array elements a[i] The difference is due to pointer variables p It doesn't always point to the first address of an array element &a[0], So only if the pointer variable p Points to the first address of an array element
&a[0] Time ,*（p+i） That's right a[i] References to , otherwise , If the 1 The operation changes the pointer variable p The direction of , send p point a[i], that *） That's right a[i] References to .
（2） Array name a Is an address constant , Its value cannot be changed by an assignment operation . Pointer variable p It's a variable , Its value can be changed by assignment , So that p Points to other elements in the array .
（3） although p+1 and p++ Both point to the next element of the cell to which the current pointer points, but p+1 Does not change the direction of the current pointer , and p++ Equivalent to execution p=p+1, therefore p++ The operation changed the pointer p
The direction of , Represents a pointer variable p Move forward to point to the next element .
（4）p+1 increase 1*sizeof（ The base type of the pointer ）.
for example ：
# include <stdio.h> int main(void) { int a[] = {1, 2, 3, 4, 5}; int *p = a;
printf("p = %d, p + 1 = %d\n", p, p+1); return 0; }
The output is ：
p = 1638196, p + 1 = 1638200

reference ：C Practical course of Language University

Technology