What is the order of memory allocation for a two-dimensional array in C/C++ when each element occupies 2 bytes and the addresses of a[1,1] and a[2,1] are 1000 and 1010 respectively?

1 Answers
Answered by suresh

In C/C++, when each element of a two-dimensional array occupies 2 bytes and the addresses of a[1,1] and a[2,1] are specified as 1000 and 1010 respectively, the memory allocation order is determined by the row-major order. This means that elements are stored row by row in memory.

Therefore, the memory allocation for the two-dimensional array is as follows:

- Address of a[1,1] = 1000
- Address of a[1,2] = 1002
- Address of a[2,1] = 1008
- Address of a[2,2] = 1010

In summary, the memory allocation for the two-dimensional array in C/C++ is in row-major order, meaning elements are stored row by row, with each element occupying 2 bytes.

Answer for Question: What is the order of memory allocation for a two-dimensional array in C/C++ when each element occupies 2 bytes and the addresses of a[1,1] and a[2,1] are 1000 and 1010 respectively?