GATE Computer ScienceVery hardGATE CS (PYQ pattern)

An array A[-2..5][1..6][0..3] of 4-byte elements has base address 1000 (address of A[-2][1][0]). What is the address of A[3][4][2] in row-major order, and what is it in column-major order?

  1. A. 1500 and 1536
  2. B. 1532 and 1500
  3. C. 1536 and 1504
  4. D. 1536 and 1500

Correct answer: D. 1536 and 1500

Extents are 8, 6, 4. Row-major offset = ((5)*6 + 3)*4 + 2 = 134 elements, so 1000 + 4*134 = 1536. Column-major offset = (2*6 + 3)*8 + 5 = 125 elements, giving 1500.

More Programming and Data Structures (GATE) questions

Exams that ask this topic