The array pointer and pointer array are both arrays of deformation. See the following three representations:
1> char a[6]=“123456”;2> char * a[6]={“12”,“34”,“56”,“78”,“910”,“1011”};3> char(*a)[6]; char str[2][6]={"123456","234567"}; a=str;
In 1, A is an array containing six char elements, and a is the array name.
In 2, A is a pointer array. First, it is an array. The array elements are char pointers that point to strings.
In 3, A is an array pointer. First, it is a pointer. pointer A points to a char array with a length of 6.
It can be understood as follows:
The comparison between 1 and 2 is equivalent to replacing char with char *. Originally, char is placed in a, and char * is now placed *.
The comparison between 1 and 3 is equivalent to replacing a with * A. The original array name is a, And now it becomes * A, which is a pointer.
Whether it is an array pointer or a pointer array, the key is whether a is replaced or char is replaced. If a is replaced, it becomes a pointer and an array pointer. The Char is replaced with an array, but an array with a pointer.
The following code is used:
# Include <iostream> using namespace STD; int main (void) {char STR [100] = "I love China! "; Cout <" array STR: "<STR <Endl; char * A [3] = {" I "," love "," China! "}; // Pointer array, which is an array, but put the cout pointer to char in the array <" pointer array a is: "; for (INT I = 0; I <3; I ++) {cout <A [I] <"" ;}cout <Endl; cout <"the array Pointer Points to the following array :"; char (* P) [6]; // array pointer, which is a pointer to an array of 6 char S2 [3] [6] = {"I ", "Love", "China"}; P = S2; For (INT I = 0; I <3; I ++) {cout <p [I] <"" ;}cout <Endl; getchar ();}