C language array pointer and pointer array, C language array pointer
1. array pointer:The pointer to an array is an array pointer.
Let's take a look at the following code:
# Include <stdio. h> int main (void) {int m [10]; printf ("m = % p, & m = % p \ n", m, & m ); printf ("m + 1 = % p, & m + 1 = % p \ n", m + 1, & m + 1); return 0 ;}
The result obtained by running the above Code is as follows:
In the code above, & m is a pointer to an array, that is, the array pointer. It is completely equal in the value of m, all pointing to the starting address of the same memory segment. However, their types are indeed different. M is a pointer of the int * type, and m points to an array such as int m [10]. Therefore, m + 1 is equivalent to adding sizeof (int ), it can be calculated from (0x0028FEFC-0x0028FEF8) = 4; while & m + 1 is equivalent to adding sizeof (int [10]), from calculation in (0x0028FF20-0x0028FEF8) = 40.
It can be defined as follows:
Int (* p) [10] = & m; here p is an array pointer, And here (* p) parentheses are required,() Has a higher priority than []Therefore, p is a pointer first, and then points to an array of int [10.
2. pointer array:An array composed of multiple pointers is a pointer array.
Int * p [10]; here we can compare it with the above array pointer. P is an array first, and the type is Pointer. Therefore, p is a pointer array (containing 10 pointers, such as p [0] and p [1].. P [9], each pointer type is int *), and each of its variables can be used to store the address.