Consider an array A[2 : 8, –4 : 1, 6 : 10]. Base address of array A is = 400…
2021
Consider an array A[2 : 8, –4 : 1, 6 : 10]. Base address of array A is = 400 and size of each element = 2 word per memory cell. What is the
address of A[5, –1, 8] in row major form?
- A.
628
- B.
614
- C.
630
- D.
626
Attempted by 30 students.
Show answer & explanation
Correct answer: B
Concept
For a 3-D array stored in row-major order with inclusive bounds A[L1:U1, L2:U2, L3:U3], the element address is computed from the base address by counting how many elements precede the target. Row-major varies the LAST index fastest, so the offset (in elements) is:
offset = (i − L1)·(D2·D3) + (j − L2)·D3 + (k − L3), where each Dn = Un − Ln + 1 is that dimension’s length. Address = Base + offset × (element size). Every index must have its OWN lower bound subtracted before use.
Application
Given A[2:8, −4:1, 6:10], Base = 400, element size = 2 words, target A[5, −1, 8]:
Dimension lengths: D1 = 8−2+1 = 7, D2 = 1−(−4)+1 = 6, D3 = 10−6+1 = 5.
Normalise each index by its lower bound: (i−L1) = 5−2 = 3, (j−L2) = −1−(−4) = 3, (k−L3) = 8−6 = 2.
First term: 3 × (D2·D3) = 3 × (6×5) = 3 × 30 = 90.
Second term: 3 × D3 = 3 × 5 = 15.
Third term: 2.
Offset = 90 + 15 + 2 = 107 elements.
Address = Base + offset × size = 400 + 107 × 2 = 400 + 214 = 614.
Cross-check
Re-add the parts independently: 400 + 180 (from 90×2) + 30 (from 15×2) + 4 (from 2×2) = 614. The negative lower bound −4 was handled by subtraction, −1−(−4) = +3, confirming the middle index contributes a positive offset. Result: 614.