GATE Computer ScienceHardGATE CS (PYQ pattern)

An array is declared A[L..10][−4..5] with 4-byte elements and stored in row-major order starting at address 1744. If the address of A[0][0] is 2000, what is the lower bound L, and how many bytes does A occupy?

  1. A. L = −6; 640 bytes
  2. B. L = −5; 640 bytes
  3. C. L = −7; 720 bytes
  4. D. L = −6; 680 bytes

Correct answer: D. L = −6; 680 bytes

Each row has 5 − (−4) + 1 = 10 elements = 40 bytes. &A[0][0] = 1744 + ((0 − L)·10 + (0 − (−4)))·4, so 256 = (−10L + 4)·4, giving −10L = 60 and L = −6. Rows −6..10 are 17 rows: 17 × 40 = 680 bytes (taking 16 rows is the off-by-one slip).

More Compiler Design questions

Exams that ask this topic