1. Array pointers: pointers to arrays are array pointers
Let's 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;}
Run the above code to get the results such as:
In the above code, &M is a pointer to an array, and the array pointer, which is exactly equal to m in value, points to the starting address of the same memory. But they are of different types. where M is a pointer to an int * type, and &m points to an array such as int m[10], which is an array pointer, so m + 1 equals sizeof (int), which can be computed (0x0028fefc-0x0028fef8) = 4; &m + 1 corresponds to the addition of sizeof (INT[10]), by the calculation in (0X0028FF20-0X0028FEF8) = 40.
can have the following definition:
int (*p) [Ten] = &m; Here p is an array pointer, and here (*p) The parentheses are required,() the precedence is higher than [], so p is first a pointer, and then points to an array of int [10].
2. Array of pointers: arrays of multiple pointers are arrays of pointers
int *p[10]; This can be compared to the above array pointers. P is first an array, and then the type is a pointer, so p is an array of pointers (with 10 pointers, such as p[0], p[1] ... P[9], each pointer is of type int *), each of its variables can be used to store the address.
Array pointers and arrays of pointers in C language