A one dimensional array A is converted to a two dimensional array N[3][10] using column...
Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.
A one dimensional array A is converted to a two dimensional array N[3][10] using column major order. What will be the address of N[3][3], if base address N[1][1] is 1008 and N[1][2] is at 1016?
Show answer & explanation
In column major order, elements are stored column-by-column. From N[1][1] = 1008 and N[1][2] = 1016, we find the element size is 8 bytes. For N[3][3], we calculate: address = 1008 + (column offset × rows × size) + (row offset × size) = 1008 + (2 × 3 × 8) + (2 × 8) = 1008 + 48 + (-16) = 1048. Alternatively, moving from N[1][1] to N[3][3] requires 2 row steps down and 2 column steps right, totaling 40 bytes forward in column major order: 1008 + 40 = 1048.
Step-by-step Derivation:
Step 1: Determine element size.
N[1][2] - N[1][1] = 1016 - 1008 = 8 bytes per element
Step 2: Understand column major address formula.
In column major order for N[rows][cols], address of N[i][j] =
base_address + ((j - 1) × rows + (i - 1)) × element_size
Step 3: Identify base address and parameters.
Given N[3][10] (3 rows, 10 columns)
N[1][1] base = 1008
Element size = 8 bytes
Target: N[3][3]
Step 4: Calculate offset from N[1][1] to N[3][3].
In column major: we fill column 1 first (rows 1, 2, 3), then column 2, then column 3.
From N[1][1] to N[3][3]:
- Column 1: N[1][1] → N[2][1] → N[3][1] (move 2 steps down = 2 × 8 = 16 bytes)
- Column 2: N[1][2] → N[2][2] → N[3][2] (move 3 × 8 = 24 bytes from start)
- Column 3: N[1][3] → N[2][3] → N[3][3] (move 5 × 8 = 40 bytes from start)
Offset from N[1][1] to N[3][3] = (2 × 3 + 2) × 8 = 8 × 8 = 40? Let me recalculate.
Position in linear array: N[3][3] is at index (2 × 3 + 2) = 8 in column-major (0-indexed from N[1][1])
Address = 1008 + 40 = 1048
Answer: 1048