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?
Answer: D. 15i + j + 100 — For a two-dimensional array stored in row-major order, the address of A[i][j] is given by Address = Base address + (i × number of columns + j) × element size.…
- A.
i + 15j + 100
- B.
10i + j + 100
- C.
i + 10j + 100
- D.
15i + j + 100
Attempted by 342 students.
Show answer & explanation
Correct answer: D
For a two-dimensional array stored in row-major order, the address of A[i][j] is given by Address = Base address + (i × number of columns + j) × element size. The number of columns here is the array's declared size for that dimension — fixed by how the array was declared, not by where index numbering starts (0-based or 1-based).
Applying this to A[10][15] with base address 100:
The array is declared as A[10][15], so it has 10 rows and 15 columns; the number of columns = 15. Each element takes 1 memory location, so element size = 1.
Substitute into the row-major formula: Address(A[i][j]) = 100 + (15i + j) x 1.
Simplify: Address(A[i][j]) = 15i + j + 100.
This also settles the reported doubt: does a lower bound of 0 push the column count to 16? No — A[10][15] already fixes the column count at 15; a lower bound of 0 only numbers those columns 0 through 14 (15 values), it does not add a 16th column. Check with the first and last elements of row 0: A[0][0] = 100 (the base) and A[0][14] = 100 + 14 = 114, so row 0 occupies exactly 15 addresses (100 to 114) — confirming 15 columns, not 16.
So the address of A[i][j] is 15i + j + 100.