A two-dimensional array A of 4-byte elements is stored in column-major order starting at address 1000, with indices starting at 0. What is the address of A?
Correct answer A. 1212
Explanation
In column-major order, whole columns are stored consecutively, so address = base + (j × number of rows + i) × size. That gives 1000 + (5 × 10 + 3) × 4 = 1000 + 53 × 4 = 1212. Fortran and MATLAB use column-major order, while C and C++ use row-major, which would produce 1260 for the same element.
Answer checked How we write and check questions
Discussion