Pointer to an entire row in a 2-D array

arrays, c, pointers

Solution

As per my understanding, a is double pointer of type int.

You are wrong. `a` is of type array of arrays of `int`. Array names converted to pointer to its first element, except when it is an operand of `sizeof` and unary `&`.

Also `a[0]` points to the row `0`, `a[1]` points to row `1`..and so on.

No. `a[0]` points to the first element of row `0` and `a[1]` points to the first element of row `1` after decay. `&a[0]` will give you the address of row `0`

p = &a[0];  // Equivalent to p = a 

Problem

Suppose I declare a 2-D array as: ``` int a[10][10]; ``` As per my understanding, a is double pointer of type int. Suppose I declare a pointer to an entire row as follows. ``` int (*p)[10]; ``` Also `a[0]` points to the row 0, `a[1]` points to row 1...and so on. So I tried to initialise p as ``` p = a[0]; /* so that p can point to row 0 */ ``` I get a compiler warning of incompatible pointer assignment. But if i write ``` p = a; ``` This works fine. Can someone tell me what I am undertaking wrong here?

Original source

Related problems