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,784
  • 4
  • 24
  • 36
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
  • 239,568
  • 38
  • 324
  • 436
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
  • 53,300
  • 8
  • 96
  • 166