C/C++ array of pointers

array of pointer types

When defining an array, we need to specify the type of elements stored in the array. For example:

int array[6]; //Define the array, the array has 6 elements, and the elements are int type;

char array[6]; //Define the array, the array has 6 elements, and the elements are char type;

double array[6]; //Define the array, the array has 6 elements, and the elements are of double type;

It can be seen that the "data type" in front of the array name defines the type of elements stored in the array. Then, after learning about pointers, we know that pointers are also a data type, for example:

int* p; //Define the pointer variable p, the variable is int* type;

char* p; //Define the pointer variable p, the variable is char* type;

Then, if we want to store the pointer variable p in an array, then the type of the array element is the pointer variable type. For example:

int* array[6];

At this point, define the array array, the array has 6 elements, and the elements are of type int*; then, the array elements are arrays of pointer type, which we call: pointer array. The definition format of pointer array is as follows:

Data type name* array name[array length];

At this point, an array is defined, and the type of the elements in the array is "data type name *", which is a pointer type. The following is an example program test:

Guess you like

Origin blog.csdn.net/luyao3038/article/details/130136162