A three dimensional array in C++ is declared as: int A[a][b][c];Consider that…
2023
A three dimensional array in C++ is declared as:
int A[a][b][c];Consider that array elements are stored in row-major order and indexing begins from 0.
Here, the address of an item at the location A[r][s][t] computed in terms of word length w of an integer is:
- A.
&A[0][0][0]+w(b⋅c⋅s+c⋅r+t)
- B.
&A[0][0][0]+w(b⋅c⋅r+c⋅s+t)
- C.
&A[0][0][0]+w(a⋅b⋅r+c⋅s+t)
- D.
&A[0][0][0]+w(a⋅b⋅s+c⋅r+t)
Attempted by 58 students.
Show answer & explanation
Correct answer: B
For a 3D array in row-major order, the offset is calculated by multiplying indices by dimensions of subsequent arrays. The total offset equals r*b*c + s*c + t. Multiplying by word length w and adding the base address gives the final memory location.
A video solution is available for this question — log in and enroll to watch it.