Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - What's the difference between int (*a)[ 10] and int *a[ 10]? I hope it can be detailed!
What's the difference between int (*a)[ 10] and int *a[ 10]? I hope it can be detailed!
Int *a[ 10]: array pointer. Array a contains 10 int pointers.

Int (* a) [10]: A is a pointer to an array. This array has 10 int elements.

int *a[ 10]

First find the declarator A, and then look to the right. There is a [] indicating that A is an array, and then looking to the left, it is an int *, indicating that every element in the array is an int *. This is an array of integer pointers.

int(*a)[ 10]

Find the declarant A first, enclose it in brackets, look at the one in brackets (with high priority) first, and then look to the right. No, look to the left, it's *, which means S is the pointer. What pointer? Look outside the brackets, first look at the right, there is an array, indicating that A is a pointer to the array, and then look at the left, indicating that every element of the array is an int. This is a pointer to an array that holds int.

example

int * p[ 10];

int(* q)[ 10];

printf( "*p[ 10]: %d\n ",sizeof(p));

printf((* q)[ 10]:% d \ n ",sizeof(q));

The result is:

*p[ 10]: 40 // Description p is the array name.

(*q)[ 10]: 4 // Q is a pointer.