ProgrammingModerateHCL · Tech Mahindra pattern

int a[3][4]; is stored in row-major order starting at address 1000, with 4-byte int. What is the address of a[2][1]?

  1. A. 1009
  2. B. 1040
  3. C. 1020
  4. D. 1036

Correct answer: D. 1036

Row-major: address = base + (row × columns + col) × size = 1000 + (2 × 4 + 1) × 4 = 1000 + 36 = 1036. 1020 comes from the column-major formula (1 × 3 + 2) × 4.

More C Programming questions

Exams that ask this topic