GATE Computer ScienceHardGATE CS (PYQ pattern)

Only the lower triangle (i ≥ j) of a 10 × 10 matrix A[1..10][1..10] of 4-byte elements is stored, packed into consecutive words starting at address 3000. What is the address of A[7][4] if the triangle is stored row by row, and if it is stored column by column?

  1. A. 3096 row-wise, 3120 column-wise
  2. B. 3100 row-wise, 3124 column-wise
  3. C. 3096 row-wise, 3132 column-wise
  4. D. 3084 row-wise, 3108 column-wise

Correct answer: A. 3096 row-wise, 3120 column-wise

Row-wise: rows 1..6 hold 1 + 2 + … + 6 = 21 elements, then A[7][4] is the 4th of row 7: offset 21 + 3 = 24, address 3000 + 96 = 3096. Column-wise: columns 1..3 hold 10 + 9 + 8 = 27 elements, and column 4 starts at row 4, so A[7][4] is at position 7 − 4 = 3 in it: offset 30, address 3120.

More Compiler Design questions

Exams that ask this topic