GATE Computer ScienceHardGATE CS

An array A[2..6][−1..4][0..5] of 4-byte elements has base address 1000. The address of A[4][2][3] is computed in row-major order and, separately, in column-major order. By how many bytes is the column-major address greater than the row-major address?

  1. A. 48
  2. B. 56
  3. C. 64
  4. D. 72

Correct answer: B. 56

The dimension sizes are 5, 6 and 6. Row-major offset = ((4 − 2)·6 + (2 + 1))·6 + 3 = 93 elements, so the address is 1372. Column-major offset = ((3·6 + 3)·5) + 2 = 107 elements, address 1428. The difference is 14 elements = 56 bytes.

More Compiler Design questions

Exams that ask this topic