Detailed Print – Computer Sir Ki Class  Solved Problem#CPP#5959

## Problem Statement - 2-D Array Element Address Calculation

A two dimensional array ARR is stored in the memory along the row with each of its elements occupying 4 bytes. Find the address of the element ARR, if the element ARR  is stored at the memory location 15000.

## Solved Problem Understanding

```Loc(ARR[I][J]) along the row
=BaseAddress + W [( I – LBR)*C + (J – LBC)]
(where C is the number of columns, LBR = LBC = 0
LOC(ARR)
= BaseAddress + W [ I*C + J]
15000 = BaseAddress + 4[10*20 + 5]
= BaseAddress + 4[200 + 5]
= BaseAddress + 4 x 205
= 14180
LOC(ARR)= 14180 + 4[30 * 20 + 10]
= 14180 + 4 * 610
= 14180 + 2440
= 16620
OR
LOC(ARR)
= LOC(ARR)+ W[( I-LBR)*C + (J-LBC)]
= 15000 + 4[(30-10)*20 + (10-5)]
= 15000 + 4[ 20*20 + 5]
= 15000 + 4 *405
= 15000 + 1620
= 16620
OR
Where C is the number of columns and LBR=LBC=1
LOC(ARR)
15000 = BaseAddress + W [(I-1)*C + (J-1)]
= BaseAddress + 4[9*20 + 4]
= BaseAddress + 4[180 + 4]
= BaseAddress + 4 * 184