Neer Neer - 2 months ago 7
C Question

What does int (*ar) [] declaration mean in C?

What is the difference between these two in C. The first one is array of pointers.
My main confusion is about the second declaration. What does it declare. Aren't the two the same ?

int *p []={&i,&j,&k};

int (*ar) [];

Answer Source

The two are not the same. The second is a pointer to an array of int.

You can use such a declaration as a function parameter when passing a 2D array as a parameter. For example, given this function:

void f(int (*ar)[5])    // array size required here to do pointer arithmetic for 2D array

You could call it like this:

int a[5][5];

Another example as a local parameter:

int a[5] = { 1,2,3,4,5 };
int (*ar)[];   // array size not required here since we point to a 1D array
int i;

ar = &a;
for (i=0;i<5;i++) {
    printf("a[%d]=%d\n", i, (*ar)[i]);