int a[3][4] = { {0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11} } The C compiler would store 3 * 4 ints, which would be 4 bytes each 3 * 4 * 4 = 48 bytes total. The values would be written one row after another: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}(Edited: 2021-11-03)
Mem alloc in C:
For an array Size of an int in C is 4 bytes
Memory = 3 * 4 * 4 = 48 bytes
Since this in an array there would be a contiguous series of 48 bytes allocated to this array This array would be written
a[0][0] a[0][1] a[0][2] a[0][3] a[1][0] a[1][1] a[1][2] a[1][3] a[2][0] a[2][1] a[2][2] a[2][3]
in integers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
for a[0][0] the bytes would would be 0000 0000 0000 0000 0000 0000 0000 0000(Edited: 2021-11-03)
A single int is 4 bytes. In a[3][4] there are 3 rows by 4 columns. 4 bytes * 3 * 4 = 48 bytes. The values are written in memory in order by consecutive rows: {0 1 2 3 4 5 6 7 8 9 10 11}(Edited: 2021-11-03)
(n * m) * sizeOf(T), n = 3, m = 4, T = integer (3 * 4) * 4 bytes = 12 * 4 bytes = 48 bytes for the whole matrix It would be stored in the order of the rows and go from the first element of the array to the last within those rows. Ex: a[0][1] = 00000000|00000000|00000000|00000001(Edited: 2021-11-03)
It would allocate 48 bytes of memory for this array. 3 * 4 * 4 The way that the values would be written in memory is one row after another. For example: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}