An array A of 2-byte elements is stored in row-major order with base address 200, and indices start at 1. What is the address of A?
Correct answer B. 218
Explanation
With 1-based indices you must subtract the lower bounds first: address = base + ((i − 1) × columns + (j − 1)) × size. That is 200 + ((3 − 1) × 4 + (2 − 1)) × 2 = 200 + 9 × 2 = 218. Forgetting to subtract the lower bounds, a frequent error, shifts the answer by one row and one element.
Answer checked How we write and check questions
Discussion