Array of pointers
An array of pointers is a special kind of array that holds all the memory addresses of the same data type. The pointer array is defined in the form:
Data type * array name [length];
For example:
const char *c[4] = {"We", "USA", "Rassia", "Japan"}; Defines a constant-character pointer array of length 4, pointing the array element to 4 string constants, respectively
int i;
for (i = 0; i < 4; i++)
{
Puts (* (c + i)); The string that the array-pointer array element points to
}
A pointer to a constant must be defined with const as a constant pointer to avoid modifying the data pointed to by the pointer to cause a program error. Because [] the symbol is higher than the indirect operator *, the first is the array form c[4], then the * binding, so that the pointer array contains 4 pointers c[0], c[1], c[2], c[3, respectively, pointing to the first address of 4 strings.
pointer Variable
A pointer variable can point to another pointer variable, rather than passing the memory address of a pointer variable to another pointer variable, defining a pointer variable that points to a pointer type, which can be called a double pointer. The dual pointer is defined in the form:
Data type * * variable name;
It uses 2 indirect operators, as shown in the following example:
int I, *PI, **dpi; Declare integer variable i, integer pointer variable pi and integral type double pointer variable dpi
PI = &i; Assigning the address of the variable i to the integer pointer variable pi
DPI = π Assigns an integer pointer variable pi address to the integer double pointer variable dpi
**dpi = 100; Indirectly referencing the variable i, assigning the variable i
printf ("%d", I); Value of output variable i
The double pointer variable dpi is defined in the code, and the double pointer variable to the pointer variable is the memory address of the pointer variable itself must be obtained using the address operator. By indirectly referencing a variable that is pointed through a dual pointer variable, you need to complete the double operation with 2 address operators because you want to get the address of the pointer variable first and then obtain the memory address that is saved in the pointer variable.