UGC NET CS 2023Data Structures and Algorithms › Data StructuresVerified
UGC NET CS 2023 PYQ: A three dimensional array in $\mathrm{C}++$ is declared as int $\mathrm{A}[\mathrm{a}][\mathrm{b}]$ [c].…
A three dimensional array in $\mathrm{C}++$ is declared as int $\mathrm{A}[\mathrm{a}][\mathrm{b}]$ [c]. Consider that array elements are stored in row major order and indexing begin from 0. Here the address of an item at the location $\mathrm{A}[\mathrm{r}][\mathrm{s}][\mathrm{t}]$ computed in terms of word length $\mathrm{w}$ of an integer is
- A& A [0] [0] [0] $+\mathrm{w}\left(\mathrm{b}^{*} \mathrm{c}^{*} \mathrm{~s}+\mathrm{c}^{*} \mathrm{r}+\mathrm{t}\right)$
- B& A [0] [0] [0] $+w\left(b * c^{*} r^{*}+c^{*} s+t\right)$Correct answer
- C& A [0] [0] [0]+w $\left(\mathrm{a}^{*} \mathrm{~b}^{*} \mathrm{r}^{*}+\mathrm{c} * \mathrm{~s}+\mathrm{t}\right)$
- D& A [0] [0] [0] $+w\left(a^{*} b^{*} s+c^{*} r+t\right)$
Answer
(B) & A [0] [0] [0] $+w\left(b * c^{*} r^{*}+c^{*} s+t\right)$
Approach
Apply the row-major address formula for a 3D array.
Reviewed by UGC IQ Editorial Team.