Data Structures & AlgorithmsHardTCS NQT · Infosys pattern

A 2-D array A[10][20] (indices from 0) of 4-byte integers is stored in COLUMN-major order starting at address 1000. What is the address of A[5][7]?

  1. A. 1328
  2. B. 1300
  3. C. 1428
  4. D. 1296

Correct answer: B. 1300

In column-major order the 7 whole columns before it (10 elements each) come first, then 5 elements: offset = (7 × 10 + 5) × 4 = 300, so 1300. 1428 is the row-major answer, (5 × 20 + 7) × 4 + 1000.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic