Consider 2 dimensional array A[10][15]. Assume that each element takes one…
2023
Consider 2 dimensional array A[10][15]. Assume that each element takes one memory location and base address of array A is 100. Consider the lower bound of row and column as 0. What is the address of A[i][j] if array A is stored in row major form?
- A.
i + 15j + 100
- B.
10i + j + 100
- C.
i + 10j + 100
- D.
15i + j + 100
Attempted by 140 students.
Show answer & explanation
Correct answer: D
In row-major order, address(A[i][j]) = base address + (i x number of columns + j) x element size.
Here base address = 100, number of columns = 15, and each element takes one memory location.
So address(A[i][j]) = 100 + 15i + j.