Two Dimensional Array Address Calculation Questions

Q1:An array P[50][60] is stored in the memory along the column with each of the element occupying 2 bytes, find out the memory location for the element P[10][20], if the Base Address of the array is 6800.
Ans: Given Number of Rows, R=50
Number of Columns, C=60
Lower Bound of Row, LBr=0
Lower Bound of Column, LBc=0
size or width of each element of array, w= 2 bytes
Base address, BA = 6800
To find address of P[10][20], i=10 and j=20
Now, Address of P[10][20] in Column Major Form = BA + w[ (i-LBr) + R (j-LBc) ]
=6800 + 2[ (10-0) + 50 (20-0) ]
= 6800 + 2[ 10 + 50 (20) ]
= 6800 + 2[ 10 + 1000 ]
= 6800 + 2 [1010]
= 6800 + 2020
= 8820

Q 2: An array P[35][14] is stored along the column with each of its elements occupying 8 bytes. Find out the base address and the address of an element P[2][5], if the location P[5][10] is stored at the address 4000.
Ans: Given Number of Rows, R=35
Number of Columns, C=14
Lower Bound of Row, LBr=0
Lower Bound of Column, LBc=0
size or width of each element of array, w= 8 bytes
Given address of P[5][10] = 4000, Here i=2 and j=5
Now, Address of P[5][10] in Column Major Form = BA + w[ (i-LBr) + R (j-LBc) ]
4000=BA + 8[ (5-0) + 35 (10-0) ]
4000 = BA + 8[ 5 + 35 (10) ]
4000 = BA + 8[ 5 + 350 ]
4000 = BA + 8 [355]
4000 = BA + 2840
BA= 4000 – 2840 = 1160
Now address of an element P[2][5] in column major form ( Here, i=2, j=5 ) = BA + w[ (i-LBr) + R (j-LBc) ]
= 1160 + 8[ (2-0) + 35 (5-0) ]
= 1160 + 8[ 2 + 35*5]
= 1160 + 8[2 + 175]
= 1160 + 8 [177]
= 1160 + 1416
= 2576

Q3: An array Arr[50][30] is stored along the row with each of its elements occupying 4 bytes. Find out the base address and the address of an element Arr[15][25], if the location Arr[15][20] is stored at the address 8000.
Ans: Given Number of Rows, R=50
Number of Columns, C=30
Lower Bound of Row, LBr=0
Lower Bound of Column, LBc=0
size or width of each element of array, w= 4 bytes
Given address of P[15][20]( i=10 and j=20) = 8000
Now, Address of P[15][20] in Row Major Form = BA + w[ C(i-LBr) + (j-LBc) ]
8000 = BA + 4 [30 (15-0) + (20-0) ]
8000 = BA + 4 [30(15) + (20) ]
8000 = BA + 4 [450 + 20 ]
8000 = BA + 4 [470]
8000 = BA + 1880
BA= 8000-1880 = 6120
Now address of P[15][25] in Row Major Form = BA + w[ C(i-LBr) + (j-LBc) ]
= 6120 + 4 [30(15-0) + (25-0)]
= 6120 + 4[450 + 25]
= 6120 + 4[475]
= 6120 + 1900
= 8020

Q4: An array P[50][60] is stored in the memory along the row with each of the element occupying 8 bytes, find out the memory location for the element P[5][15], if the Base Address of the array is 8800.
Ans: Given Number of Rows, R=50
Number of Columns, C=60
Lower Bound of Row, LBr=0
Lower Bound of Column, LBc=0
size or width of each element of array, w= 8 bytes
Base address, BA = 8800
To find address of P[5][15], i=5 and j=15
Now, Address of P[5][15] in Row Major Form = BA + w[ C(i-LBr) + (j-LBc) ]
=8800 + 8[ 60(5-0) + (15-0) ]
= 8800 + 8[ 300 + 15 ]
= 8800 + 8[ 315 ]
= 8800 + 2520
= 11320

error: You can only copy the programs code and output from this website. You are not allowed to copy anything else.