C pointer declaration for pointing to a row of 2-d array

c

Solution

`> "But I do not understand the syntax for declaring p"`

So `p` is declared as:

int (*p)[COLS];

It's a pointer to an array of `int`s which is `COLS` in size.

`> "What does that mean and how do I remember it?"`

Here's how you can tell, use the spiral rule and start by working in the `()`s:

    ( p)                    p 
    (*p)                    p is a pointer
    (*p)[    ]              p is a pointer to an array
int (*p)[    ]              p is a pointer to an array of ints
int (*p)[COLS]              p is a pointer to an array of ints of size COLS

Of course you could always cheat to get the answer too:

`> "what does this syntax mean in terms of operator precedence?"`

In the C Language, `[]` has precedence over the unary `*`, that means you need the `()` in order for `p` to be a pointer to an array of `int`s, instead of an array of pointers to `int`s.

Problem

I came across this declaration in KN King's book on Page 269 ``` int a[ROWS][COLS], (*p)[COLS]; p = &a[0]; ``` `p` now points to the first row of 2-d array. I understand why `a[0]` points to first row of 2-d array. But I do not understand the syntax for declaring `p`. What does that mean and how do I remember it? What are the parens around `*p` doing ? `(*p)` what does this syntax mean in terms of operator precedence?

Original source