451 views
2 votes
2 votes
Let A be an array with 5 rows and 10 columns. Assume base address is 100 and each element requires 4 bytes. Find the address of A [4,9], if array is stored in row major order?

a)252

b)352

c)152

d)452

1 Answer

1 votes
1 votes

$\begin{bmatrix} &A_{1,1} &A_{1,2} &A_{1,3} &. &. &. &. &A_{1,10} \\ &A_{2,1} &A_{2,2} &A_{3,3} &. &. &. &. &A_{2,10} \\ &.. & & & & & & & & \\ &.. & & & & & & & & \\ &A_{5,1} &A_{5,2} &A_{5,3} &. &. &. &. &A_{5,10} \end{bmatrix}$

In row major order, elements are entered row by row in an array. ie; If the base address is $0$, then $A_{1,1}$, $A_{1,2}$,$A_{1,3}$... $A_{1,10}$ are entered first to locations 0 to 9. Now $A_{2,1}$ will occupy the position 10. So in this case the element $A_{4,9}$ will occupy the location $38$.

ie; address of $i,j$ th element = $n*(i-1) + (j-1)$, where $n$ is the total number of columns.

 

So in general, for row major order, address of $A_{i,j}$ = Base address $+$ Size of element $*(n(i-1)+(j-1))$

Given that base address $= 100$ and size of an element $=4\space bytes$

Address of the element $A_{4,9}$ 

$=100+4*(10(4-1)+(9-1))$ 

$= 100+4*38 = 252$.

 

Related questions

1 votes
1 votes
1 answer
1
Human asked Oct 8, 2018
625 views
how the answer is 23699?For column major order I get answer as 80039.Even if i go by row major order the answer I get is 23599
1 votes
1 votes
0 answers
3
0 votes
0 votes
1 answer
4
Kashyap Avinash asked Dec 9, 2016
633 views
Confusion in last printf Statement..Can anyone explain what printf Statement want to say...