1

I Have read some where about this type declaration. Declaration is:

int (*arr)[5];

i'm little bit confused with this type declaration.Actually what is the meaning of this declaration and when do we use it.

3 Answers3

3
int *arr[5]

arr is array of 5 pointers

int (*arr)[5]

arr is a pointer to an array of 5 integer elements

Check the code below:

int a[5] = { 1,2,3,4,5};
int (*arr)[5] = &a;
printf("%d",(*arr)[2]);

Now the array element can be accessed like

(*arr)[i] not *arr[i]

Gopi
  • 19,679
  • 4
  • 22
  • 35
2

It means arr is a pointer to an array of 5 integers. Compare with the less-confusing array of five pointers:

int* arr[5];

That's why you need the parentheses.

John Zwinck
  • 223,042
  • 33
  • 293
  • 407
2

According to the “declaration follows use” rule:

  • (*arr)[i] is an int, where i <= 5, therefore
  • *arr is an int[5], an array of five integers, therefore
  • arr is an int (*)[5], a pointer to an array of five integers.
Jon Purdy
  • 51,678
  • 7
  • 93
  • 161