Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do these declarations mean in C? [duplicate]

Tags:

c

The declarations

int arr[10];
int *arr1[10];

are straightforward. The first declares an array of 10 integers while the second declares a 10 value array of pointers to int (int *).

Now, consider these declarations:

int (*arr2)[10];
int *(*arr3)[10];

What do these even mean? Considering the parenthesis, they are trying to dereference arr2 and arr3 in the declaration? Is this even possible?

Can anyone answer what is the type of values stored in these arrays and if I do something like *arr2 or *arr3, what would the value be?

Also, what is the type of arr2 and arr3 now?

like image 677
Black Wind Avatar asked Feb 02 '26 06:02

Black Wind


1 Answers

In these declarations:

int arr[10];
int *arr1[10];
int (*arr2)[10];
int *(*arr3)[10];

arr is an array[10] of ints.

arr1 is an array[10] of pointers to int.

arr2 is a pointer to an array[10] of ints.

arr3 is a pointer to an array[10] of pointers to int.

like image 119
Madagascar Avatar answered Feb 03 '26 21:02

Madagascar