What Is an Array of Pointers?
In languages such as C and C ++, an array whose array elements are all pointer variables is called a pointer array, and the elements in the pointer array must have pointer variables of the same storage type and pointing to the same data type. Pointer arrays are more suitable for pointing to several strings, making string processing more convenient and flexible. The definition of a one-dimensional pointer array is: "type name * array identifier [array length]". [1]
- Pointer array, that is to say, is an array first, and the elements of the array are pointers, that is, if the array elements are pointers of the same type, this array is called a pointer array. The so-called pointers of the same type mean that the types of objects pointed by the pointers are the same. The definition of a one-dimensional pointer array is:
- Array pointer:
#include <stdio.h> int main () { char c [] [4] = {"Brother", "Brother", "I", "Ashore", "On", "Go"}; // UTF-8: One Chinese character = 3 bytes char (* p) [4]; int i; p = c; // position pointer at c [0] for (i = 0; i <= 5; i ++) { printf ("% s,", * (p + i)); // or replace * (p + i) with * p ++ } printf ("\ n"); for (i = 5; i> = 0; i--) { printf ("% s,", * (p + i)); // or replace * (p + i) with *-p } return 0; }
- Pointer array:
#include <stdio.h> int main () { int i; char * pch [6] = {"sister", "sister", "you", "sitting", "boat", "head"}; for (i = 0; i <6; i ++) { printf ("% s,", pch [i]); } printf ("\ n"); for (i = 5; i> = 0; i--) { printf ("% s \ n", pch [i]); } return 0; }