Detailed explanation of pointer arrays and array pointers

Pointer arrays and array pointers are two common concepts in the C language. They both involve the use of pointers and arrays, but there are some subtle differences between them.

A Pointer Array is an array where each element is a pointer type. This means that the Pointer Array stores a group of pointers that can point to various types of data. The declaration format for a Pointer Array is type *array[], where type is the data type being pointed to, and array[] is the name of the Pointer Array.

For example, int *arr[5] is an array of pointers that holds 5 pointers to integer data. Each pointer can point to an integer type of data.

An array pointer is a pointer that points to an array. It is declared as type (*pointer)[size], where type is the type of array elements, pointer is the name of the pointer, and size is the size of the array.

For example, int (*ptr)[5] is a pointer to an array that contains 5 integer values. This means that ptr points to the address of an integer value, which is the starting address of the array.

In general, a pointer array is an array where each element is of pointer type; while an array pointer is a pointer that points to an array. They have some differences in terms of usage and operation, so it is important to choose the one that best fits the specific situation.

It is important to note that this is just a brief introduction, and in actual use, one must combine specific code to understand and apply it.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds