in Programming in C edited by
980 views
0 votes
0 votes
Consider 3 dimensional Array A[90] [30] [40] stored in linear array in column major order. If the base address starts at 10, The location of A [20] [20] [30] is ________.
(Assume the first element is stored at A[1][1][1] and each element take 1 memory location)
in Programming in C edited by
980 views

3 Comments

is it 23399?
0
0
its 23699
0
0
Can anybody please help me out here :(
0
0

4 Answers

2 votes
2 votes

A[1...90][1...30][1...40]

LOC(A[20][20][30]) =10 + ((20-1)*30*40 +(30-1)*30 + (20-1)) = 23699

in general for CMO:

A[1...n][1...m][1...o]

loc(A[i][j][k]) = base address + ((i-1)*#f col * #f rows + (k-1)*#f rows + j-1)*size of array

edited by

2 Comments

for cmo i  used  n dimensional  formula to evaulate ;

LIKE (E3*L2+E2)L1+E1

where l1=90 ;l2=30; l3=40

E3=29;E2=19; E1=19

and got 80039(which is ofcourse wrong).. did i used wrong formula..?
0
0
check now!
0
0
0 votes
0 votes
To access element $a_{i,j,k}$ in array $A_{p,q,r}$ for RMO with elements starting from 0, use below formula:

$a_{i,j,k} = [i(q+r) + j*r + k] size + base$

Now, modifying it for CMO with elements starting from 1:

$a_{i,j,k} = [(k-1)(p+q) + (j-1)*q + (i-1)] size + base$

I am not sure about it, so you should check it out. But this is what we get if we go with the logic of how we derive for CMO in 2-D array.
0 votes
0 votes
0 votes
0 votes

address A[k1][k2][k3]=base address +w(E3*L2+E2)L1+E1)

L1=90 ;L2=30; L3=40

E3=29;E2=19; E1=19.

reference: https://youtu.be/-LA4ZqCzajw 

Ans: 80039 in column major order

 

Related questions