6 votes 6 votes 39 ) Suppose a multidimensional array is declared as m(2:8,-4:1,6:10). If the base address is 200 and there are 4 words per memory location, then the address of A[5,-1,8] by using row order is ______. mohitbawankar asked Jan 15, 2018 mohitbawankar 15.3k views answer comment Share Follow See all 7 Comments See all 7 7 Comments reply Show 4 previous comments gauravkc commented Jan 15, 2018 reply Follow Share multidimensional array is declared as m(2:8,-4:1,6:10) How do we interpret this sentence? 0 votes 0 votes MiNiPanda commented Jan 15, 2018 reply Follow Share It is interpreted as :- A 3-D array whose frame no. Starts from 2 and ends at 8. Total no. Of frames = (8-2+1)=7 In each frame, there are (-4:1,6:10) rows and columns respectively. Which means (1-(-4)+1)=6 rows and (10-6+1)=5 columns. Ultimately, there are 7 frames and each has 6 rows and 5 columns. You can refer to the answer's diagram to get an idea. 1 votes 1 votes shristy1 commented Jul 15, 2018 reply Follow Share In A[i][j][k] an array of 3 dimensions isnt i == row, j== column and k== height or frame ; In above question it is represented as i== height , j== row and k==column. 0 votes 0 votes Please log in or register to add a comment.
Best answer 9 votes 9 votes I have drawn a sketch of 3-D array to give a rough idea about how it looks like..it consists of many 2-D arrays also referred as Frames. First see the no. of frames already crossed(given by the 1st dimension).. this means finding out how many elements of frames have already been covered. For that find (no. Of rows * no. Of columns)*no. Of frames given. After reaching that particular frame, treat the sum as a simple 2-D array sum. MiNiPanda answered Jan 15, 2018 • selected Feb 2, 2018 by sumit goyal 1 MiNiPanda comment Share Follow See all 10 Comments See all 10 10 Comments reply sunil sarode commented Jan 19, 2018 reply Follow Share can you please explain how it will work with column major Suppose a multidimensional array is declared as m(1:8,-5:5,-10:5). If the base address is 200 and there are 4 words per memory location, then the address of A[3,3,3] by using column order is ______. 0 votes 0 votes MiNiPanda commented Jan 19, 2018 reply Follow Share @ sunil sarode Do you know it's ans? i am getting 2212. 0 votes 0 votes sunil sarode commented Jan 19, 2018 reply Follow Share 5240 and thanks for reply :) 0 votes 0 votes MiNiPanda commented Jan 19, 2018 reply Follow Share #rows = 5-(-5)=1 =11 #columns = 5-(-10)+1 =16 The 1st part should remain same like frame 1 and 2 are fully covered in A[3,3,3]. So 2frames*#rows*#columns = 2*11*16 = 352 --(i) The 2nd part changes for column major : A[i,j,k] (k-LSB)*#rows + (j-LSB) By putting the values i got 143+8 --(ii) i) + ii) = 503. Base + 4B*503 =2212 I don't know how 5240 can be the answer. If you know the solution please share it here. 0 votes 0 votes sunil sarode commented Jan 19, 2018 reply Follow Share it is not natural for me hence i ask you Address = 400 + 4 * 1210 = 5240 0 votes 0 votes MiNiPanda commented Jan 19, 2018 reply Follow Share Here they are finding the address of A[5,-1,8] right? You asked me to find A[3,3,3]. 0 votes 0 votes sunil sarode commented Jan 19, 2018 reply Follow Share ok i am sorry i did not notice that. I am following this for row major and what change i need to do for columns major ? int k = C[i][j][k]. It means we have to cross, i 2D arrays, j 1D arrays, and k elements to reach our required element. = B.A + (i_2D_arrays*no._elements_In_1_2D_Array + j*no._elements_in_1_1D_Array + k)*intsize =B.A + (i_2D_arrays*no._elements_In_1_2D_Array*instsize + j*no._elements_in_1_1D_Array*intsize + k*intsize) 0 votes 0 votes MiNiPanda commented Jan 19, 2018 reply Follow Share Address = B.A + ((i-LSB)_2D_arrays*no._elements_In_1_2D_Array*instsize + (k-LSB)*no._of_rows*intsize + (j-LSB)*intsize) The bold parts are the correction. You were almost right :) 1 votes 1 votes HIMANSHU KUMAR 3 commented May 30, 2018 reply Follow Share Given a 3D array A[1:8,-5:5,-10:5] stored in a column major order, if the base address is 400 and size of an element is 4 byte, what is the address of A[3][3][3]? I'm also getting 2412 CMO=(11*16*2+13*11+8)*4+400 What is the correct answer? 0 votes 0 votes Rohit Mahali commented Aug 1, 2018 reply Follow Share Column major order 0 votes 0 votes Please log in or register to add a comment.
1 votes 1 votes answer is very simple to find the address of multidimension array like in above problem if you go from left to right direction then we find the adress of element in row major order and if you are go from right to left direction then you find the address of element in column mjor order A[lb1......ub1][lb2.......ub2][lb3.......up3] is given array then Adress of the A[l][m][n]=base adress +[(l-lb1)(ub2-lb2+1)(ub3-lb3+1)+(m-lb2)(ub3-lb3+1)+n-lb3]*w put the value and find the answer,anwer will come in this case 628 Chandrabhan Vishwa 1 answered Aug 1, 2018 Chandrabhan Vishwa 1 comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes Address calculation for N-D Array Rohit Mahali answered Aug 1, 2018 Rohit Mahali comment Share Follow See all 0 reply Please log in or register to add a comment.