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

Solve the following.

A matrix P[-10…10, 1…10] is stored in the memory with each element requiring 2 bytes of storage. If…

A matrix $P[-10\dots10, 1\dots10]$ is stored in the memory with each element requiring 2 bytes of storage. If the base address is 2000, find the address of $P[5][6]$ when the matrix is stored Row Major wise.

Answer

Answer

Row Major formula: Addr(P[i][j]) = Base + W × [ (i - LR) × NC + (j - LC) ] Here LR (lower row bound) = -10, LC (lower column bound) = 1, UC (upper column bound) = 10, so NC (number of columns) = UC - LC + 1 = 10; W = 2, Base = 2000, i = 5, j = 6. Addr(P[5][6]) = 2000 + 2 × [ (5-(-10)) × 10 + (6-1) ] = 2000 + 2 × [ 15 × 10 + 5 ] = 2000 + 2 × 155 = 2000 + 310

Final answer: 2310