in Programming in C
932 views
0 votes
0 votes
Given a 3D array A[2:8,-4:1,6:10] stored in a row major order, if the base address is 200 and size of an element is 4 byte, what is the address of A[5][-2][8]?

 

I AM GETTING ANSWER 616 ANSWER IS 608 ?????? AM I WRONG
in Programming in C
932 views

4 Comments

@Deepanshu 

https://gateoverflow.in/195348/multidimensional-aaray

I didn't go through the answer in your link properly but there is only one way to find it I believe..maybe the explanation seemed clearer to you..

You can check this link.. I tried to give an idea of how it looks..

1
1

@MiNiPanda nice method.....

IS IT SAME FOR BOTH ROW MAJOR AND COLUMN MAJOR ORDER??

1
1
No.. it's a bit different like the 2D one
0
0

3 Answers

1 vote
1 vote
I am also getting 608

A[x][y][z] = A[8-2+1][1-(-4)+1][10-6+1]. So A[7][6][5] is our 3-D array. if we go for row major  order we consider A[planes][row][columns] we need to know the address of A[5][-2][8] which is A[3][2][2] so we need to cross 3 planes means (6*5  elements in one plane) 90 element after that we need to cross 2 rows (= 10 elements) and 2 column element so the total element we need to cross is

(3*6*5)+(5*2)+2 =102

so the address of A[3][2][2] will be = 200+(102*4) = 608

4 Comments

@lakshaysaini2013

no need to call me sir.

0
0

https://en.wikipedia.org/wiki/Row-_and_column-major_order#Address_calculation_in_general 

let take A[M][N][P] ( note that all indices are starts with 0 ), and required element A[i][j][k]

i got the row major order but for column major order using the above given concept i got 

k*M*N+j*M+i

0
0
i am not getting, how they calculated...

i consider, Column Major Order as let take A[3][4][5]

000 010 020 030 100 110 120 130 200 210 220 230

001 011 021 031 101 111 121 131 201 211 221 231

002 012 022 032 102 112 122 132 202 212 222 232

003 013 023 033 103 113 123 133 203 213 223 233

004 014 024 034 104 114 124 134 204 214 224 234

if this order is right, then My formula should be right.
0
0
1 vote
1 vote

I think it will help you

4 Comments

check it whrever you going to wrong and correct your mistake.
0
0

@Shubham Aggarwal bro ur answer is correct but i never use this method so little confused

0
0
ok but this is genral approach i think you should follow this for more accurate answer anyway every question have lot of solution do whichever you like most.
0
0

Can anyone explain me what does this notation mean??  A[2:8,-4:1,6:10]

 

0
0
0 votes
0 votes
yes 608 is the right answer.