2D array variable pointer confusion

前端 未结 5 2045
日久生厌
日久生厌 2021-01-06 03:35

I have a basic doubt in 2D arrays (C Language). Consider a declaration of a 2D array as follows

int array[3][5];

Now when I do the followin

5条回答
  •  有刺的猬
    2021-01-06 04:14

    2D arrays in C are confusing.
    array and *array are both the same pointer, but are not the same type.
    array is of type int[3][5] (which is an array, of size 5, of int[3] arrays).
    *array is the first line of array, which is of type int[3].
    array+1 means array plus one element. An element of array is int[3], so it's 12 bytes forward.
    *array+1 means *array plus one element. An element of *array is int, so it's 4 bytes forward.

提交回复
热议问题