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

Solve the following.

A matrix M[-6 … 10, 4 … 15] is stored in the memory with each element requiring 4 bytes of storage…

A matrix $M[-6 \dots 10, 4 \dots 15]$ is stored in the memory with each element requiring 4 bytes of storage. If the base address is 1025, find the address of $M[4][8]$ when the matrix is stored in column major wise.

Answer

Answer

Official answer key
Column Major formula: Address(M[I][J]) = B + W x [(J - Lc) x M + (I - Lr)], where M = number of rows. Row range -6 to 10 => M = 10 - (-6) + 1 = 17 Column range 4 to 15 => N = 15 - 4 + 1 = 12 (not needed further, column major) Given: B = 1025, W = 4, I = 4, J = 8, Lr = -6, Lc = 4 Address(M[4][8]) = 1025 + 4 x [(8-4) x 17 + (4-(-6))] = 1025 + 4 x [4 x 17 + 10] = 1025 + 4 x [68 + 10] = 1025 + 4 x 78 = 1025 + 312 = 1337

Final answer: 1337