Search code examples
carrayspointers

What is the meaning of int (*pt)[5] in c


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.


Solution

  • 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]