Consider a multidimensional array A stored in rowmajor order
Consider a multidimensional array A stored in row-major order with 22 rows and 6 columns whose subscripts start at 0. If each element occupies eight bytes, then how many bytes from the start address of A will element A[3, 5] be stored? 284 136 184
Solution
The answer is 184.
Explanation:
In an array, elements are stored sequentially in memory. So, if we have an array A[22][6], the memory allocation would be in the following sequence.
A[0][0] , A[0][1] , A[0][2] , A[0][3] , A[0][4] , A[0][5] , A[1][0] , A[1][1] , A[1][2] , A[1][3] , A[1][4] , A[1][5] , A[2][0] , A[2][1] , A[2][2] , A[2][3] , A[2][4] , A[2][5] , A[3][0] , A[3][1] , A[3][2] , A[3][3] , A[3][4] , A[3][5] , A[4][0] , ...... ,
The element A[3][5] is at 24th position. So, if each element takes 8 bytes, then, first 23 elements will take 23x8 (=184) bytes. That\'s why the element A[3][5] will be stored 184 bytes from the starting address.
