Prashnikaप्रश्निका
Code
About
‹ Back to the paper
Computer Science20202 marksNumericalArrays, StringsTool: 2D array visualiser

Solve the following.

A matrix B[10][20] is stored in the memory with each element requiring 2 bytes of storage. If the…

A matrix $B[10][20]$ is stored in the memory with each element requiring 2 bytes of storage. If the base address at $B[2][1]$ is 2140, find the address of $B[5][4]$ when the matrix is stored in Column Major Wise.

Answer

Answer

Column major formula (relative to the element whose address is known): Address of $B[I][J] = BA + W \times [(J - L_c) \times M + (I - L_r)]$ Given: number of rows $M = 10$, $W = 2$ bytes, $BA = 2140$ at $B[2][1]$, so $L_r = 2$, $L_c = 1$; $I = 5$, $J = 4$. Address of $B[5][4] = 2140 + 2 \times [(4 - 1) \times 10 + (5 - 2)]$ $= 2140 + 2 \times [30 + 3]$ $= 2140 + 66 = 2206$

Final answer: 2206