AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started
Mediumarrayaddressing

~90s

Address in a row-major array

An array A[10][20] of 4-byte integers is stored in row-major order with base address 1000, indices starting at 0. What is the address of A[3][5]?

Show the answer and the worked solution

Correct answer: C.

1260

Worked solution

  1. In row-major order the elements before A[3][5] are the three complete rows 0, 1 and 2, plus five elements of row 3.
  2. That is 3 × 20 + 5 = 65 elements.
  3. At 4 bytes each the offset is 65 × 4 = 260 bytes.
  4. The address is 1000 + 260 = 1260.

Answer: 1260.

The idea

The row-major formula is base + w × (i × columns + j). Column-major swaps the roles, using base + w × (j × rows + i), and papers often ask for both from the same array.

Shortcut. Each row is 20 × 4 = 80 bytes: three whole rows are 240 bytes and five elements add 20, so 1000 + 260 = 1260.

Common trap. 1320 is 1000 + 4 × 80, which counts row 3 itself as a whole row and ignores the column offset; only rows 0 to 2 precede it.

Address in a row-major array — Aptitude Question

Address in a row-major array: An array A[10][20] of 4-byte integers is stored in row-major order with base address… Answer and worked solution on CodeKairo.

Question

An array A[10][20] of 4-byte integers is stored in row-major order with base address 1000, indices starting at 0. What is the address of A[3][5]?

Options

  1. 1160
  2. 1200
  3. 1260
  4. 1320
Show the answer and the worked solution

Correct answer: C. 1260

Worked solution

  1. In row-major order the elements before A[3][5] are the three complete rows 0, 1 and 2, plus five elements of row 3.
  2. That is 3 × 20 + 5 = 65 elements.
  3. At 4 bytes each the offset is 65 × 4 = 260 bytes.
  4. The address is 1000 + 260 = 1260.

Answer: 1260.

The idea

The row-major formula is base + w × (i × columns + j). Column-major swaps the roles, using base + w × (j × rows + i), and papers often ask for both from the same array.

Shortcut. Each row is 20 × 4 = 80 bytes: three whole rows are 240 bytes and five elements add 20, so 1000 + 260 = 1260.

Common trap. 1320 is 1000 + 4 × 80, which counts row 3 itself as a whole row and ignores the column offset; only rows 0 to 2 precede it.

All Data Structures & Algorithms questions · placement mock tests