• edited by
2,423 views
1 1 vote
Consider a three dimensional array A[30][40][50], find  the location of the array element A[5][6][7] , if the base address of array A is 150  and each element take 4 byte of memory.

1 Answer

Best answer
5 5 votes

Note: Questions is incomplete without given the address of first element, for this solution I am assuming it to be A[0][0][0]

if given array dimension A[30][40][50] it means there are 30 frames. in each frame 40 rows & 50 columns.

array would be like [i...29][i...39][i...49]

note: for this case i=0


address of element= base address + total Bytes you have crossed to get to that element.


For R.M.O.


to get address of A[5][6][7],

we have to cross (5-i) frames and 40*50 elements in each frame total (5-i)40*50 elements


Now we have reached to the frame whose element's address we want to get, From here it is like 2D array


so, we have to cross (6-i) rows in each rows 50 elements, total (6-i)*50 elements.


now we are at row where element is, sowe just have to cross (7-i) columns to get to that element 


Therefore address will be  150+(4*((5-i)*40*50+(6-i)*50+(7-i))).  

• selected by
Position:
Show:

Related questions

5 5 votes
2 2 answers
330
330 views
GO Classes asked Jun 29
330 views
What is the output of the following code?#include <stdio.h struct Student { int roll; int marks; }; int main() { struct Student s[3] = { {1, 70}, {2, 80}, {3, 90} }; s .m...
6 6 votes
1 1 answer
209
209 views
GO Classes asked Jun 23
209 views
What will happen when the following code is compiled?#include <stdio.h int main() { int a[] = {10, 20, 30}; a = a + 1; printf("%d", *a); return 0; }$\texttt{10}$ $\texttt...
7 7 votes
2 2 answers
268
268 views
GO Classes asked Jun 23
268 views
What is the output of the following code?#include <stdio.h int main() { int a[] = {5, 10, 15, 20}; int *p = a + 1; printf("%d %d %td", *(p + 1), p , (p + 2) - a); return ...
7 7 votes
2 2 answers
314
314 views
GO Classes asked Jun 22
314 views
What is the output of the following code?#include <stdio.h int main() { int a[] = {2, 4, 6, 8, 10}; printf("%d %d %d", *a, *(a + 3), 3[a]); return 0; }$\texttt{2 6 8}$ $\...