You are right, that matrix[i][j]
is equivalent to *(*(matrix + i) + j)
, since arr[i]
is equivalent to *(arr + i)
. However, please keep in mind, that if arr
is declared as
int arr[64];
then any reference to arr
may be implicitly converted to &arr[0]
, that is a pointer to the first element. Same thing happens with arrays of arrays:
int matrix[8][8];
Here matrix
has type int[8][8]
, which is automatically converted to int (*)[8]
when you add an integer to it, as in matrix + i
. Then *(matrix + i)
has type int[8]
, which is again converted to int *
when you add j
, so *(matrix + i) + j
has type int *
, therefore *(*(matrix + i) + j)
has type int
as expected.
So the point is, that arrays are not pointers, it is just that they can be implicitly casted to a pointer to their first element.
So if you allocate arrays of arrays like above (int matrix[8][8];
), then then all elements are consecutive in memory.