How are 3D arrays stored in C?

前端 未结 8 2309
半阙折子戏
半阙折子戏 2020-11-29 23:17

I understand that arrays in C are allocated in row-major order. Therefore, for a 2 x 3 array:

0  1
2  3
4  5

Is stored in memory as

8条回答
  •  旧时难觅i
    2020-11-29 23:28

    All "dimensions" are stored consecutively in memory.

    Consider

        int arr[4][100][20];
    

    you can say that arr[1] and arr[2] (of type int[100][20]) are contiguous
    or that arr[1][42] and arr[1][43] (of type int[20]) are contiguous
    or that arr[1][42][7] and arr[1][42][8] (of type int) are contiguous

提交回复
热议问题