375 views
1 votes
1 votes
Given an array A[-1:6,-2:10]. The base address of array is 1000. If every elements takes 4 bytes for storage then compute the address of element A[5,7]

answer given is 1348

1 Answer

Best answer
1 votes
1 votes

$A[-1:6;-2:10]$

This is $8\times13$ array.

We know if indexing starting from $'0'$ so we can easily apply the formula.

Now we can convert this array into $'0'$ indexing. Add $+1$ and $+2$

$A[-1+1:6+1;-2+2:10+2]$

$A[0:7;0:12]$

Here $8\times13$ array so we can say $m\times n = 8\times13$

Now we want to find $A[5,7]$,here remember we add $+1$ and $+2$

So $A[5+1,7+2]=A[6,9]=A[i,j]$

Now,Row Major order:

$A[i,j]=$Base address$+((n*i)+j)*$Size of each element

$A[6,9]=1000+((13*6)+9)*4$

$A[6,9]=1000+(78+9)*4$

$A[6,9]=1000+(87*4)$

$A[6,9]=1000+348$

$A[6,9]=1348$

and Column Major order$:$

$A[i,j]=$Base address$+((m*j)+i)*$Size of each element

$A[6,9]=1000+((8*9)+6)*4$

$A[6,9]=1000+(72+6)*4$

$A[6,9]=1000+(78*4)$

$A[6,9]=1000+312$

$A[6,9]=1312$

If nothing is given go for Row major order.

edited by

Related questions

1 votes
1 votes
0 answers
1
deepanshu sharma 3 asked Nov 17, 2018
368 views
Consider the following recursive C function. If get (6) function is being called in main () then how many times will they get () Function be invoked before returning to ...
0 votes
0 votes
1 answer
2
[ Jiren ] asked Mar 5, 2023
334 views
0 votes
0 votes
1 answer
3
[ Jiren ] asked Mar 5, 2023
225 views
0 votes
0 votes
2 answers
4
[ Jiren ] asked Mar 5, 2023
233 views