Page 180 - C++
P. 180
if (a[i]%2= =0)
a[i]=a[i]/2;
else
a[i]=a[i]*2;
cout<<a[i]<<’,’;
}
}
(c) An array Array[20][15] is stored in the memory along column with each element occupying 8 bytes. Find
out the base address of the element Array[2][3] if the element Array[4][5] is stored at the address 1000.
(3)
Ans.
Given Data: Array[20][15] W=8 B=?
R=20 C=15 Lr = 0 Lc = 0
Address of Array [2][3] =?Address of Array[4][5] =1000.
Address of an element (I,J) in column major =B + W ( (I-Lr) + R(J-Lc ) )
Therefore 1000=B+8*((4-0)+20(5-0))
1000=B+8*(4+20*5)
1000 =B+8*104
1000=B+832
B =1000-832
B =168
Therefore Address of Array[2][3]=168+8*((2-0)+20(3-0))
=168+8*(2+20*3)
=168+8*62
=168+496
=664
OR
(c ) An array Arr[15][20] is stored in the memory along the row with each element occupying 4 bytes. Find out
the Base address of the location Arr[3][2], if the location Arr[5][2] is stored at the address 1500. (3)
Solution: Given Data: Arr[15][20] W=4 B=? R=15 C=20 Lr = 0 Lc = 0 Address of Arr[3][2] = ?
Address of Arr[5][2] = 1500.