Suppose that a C array has been declared as follows int a345
Suppose that a C++ array has been declared as follows:
int a[3][4][5];
(a) Give the access function for this array, assuming that the address of a is 1020
and int values occupy four bytes.
(b) What is the address of a[1][2][3]?
Solution
(a). The access function for this array is:
1020 + (i*20 + j*5 + k) * 4
(b). The address of a[1][2][3] is: 1020 + (1*20 + 2*5 + 3) * 4 = 1020 + (20 + 10 + 3) * 4 = 1020 + 33 * 4 = 1020 + 132 = 1052 is the address for the index: a[1][2][3].
![Suppose that a C++ array has been declared as follows: int a[3][4][5]; (a) Give the access function for this array, assuming that the address of a is 1020 and i Suppose that a C++ array has been declared as follows: int a[3][4][5]; (a) Give the access function for this array, assuming that the address of a is 1020 and i](/WebImages/10/suppose-that-a-c-array-has-been-declared-as-follows-int-a345-1004781-1761517874-0.webp)
