Pointer array: array of pointers, which is used to store pointers to arrays, which are arrays of elements that are pointers
int* a[4] means: The elements in array A are all int pointers, and the element means: *a[i] * (a[i]) is the same, because [] precedence is higher than *
Array Pointer: A pointer to an array, which is a pointer to the array
int (*a) [4] means: A pointer to array a, which is represented by an element: (*a) [i]
1#include <iostream>2 3 using namespacestd;4 5 intMain ()6 {7 intc[4]={1,2,3,4};8 9 int*a[4];//Array of pointersTen int(*b) [4];//Array Pointers one ab=&c; - - //assigning an element in array C to array a the for(intI=0;i<4; i++) - { -a[i]=&c[i]; - } + - //output look at the results +cout<<*a[1]<<endl;//Output 2 is the right acout<< (*b) [2]<<endl;//Output 3 is the right at - return 0; -}
Note: the array pointer is defined, the pointer to the first address of the array, the pointer must be given an address, it is easy to make the mistake is, do not give B address, directly with (*b) [i]=c[i] to the array b element assignment, when the array pointer does not know where to point, debugging may be correct, but the runtime must have problems, Be aware of this when using Pointers. But why does a not have to give him the address, the element of A is a pointer, in fact the for loop has already given the element in the array a address. But if you write *a[i]=c[i in the for loop], this also goes wrong.
In short, the definition of the pointer must know where the pointer points, or TRAGEDY.
pointer arrays and arrays of pointers (handling)