1.

An array Arr[35][15] is stored in the memory along the row with each element occupying 4 bytes. Find out the base address and address of an element Arr[20][5], if the location Arr[2][2] is stored at the address 3000. 

Answer»

A[35][15] => rows R=35, columns C=15

Let base address be B

Given element width W=4 bytes and A[2][2]=3000

In Row major,

 A[I][J]=B+W(C(I=lr)+(j-lc))

where lr=lowest row and lc=lowest column

A[2][2]=B+W(C(2-0)+(2-0))

3000=B+4(15(2)+2) 

3000=B+128

Base Address B=3000-128=2872

Using same formula

 A[20][5]=2872+4(15(20-0)+(5-0))

= 2872+1220

= 4092



Discussion

No Comment Found

Related InterviewSolutions