Discussion
A three dimensional array in ‘C’ is declared as int A[x][y][z]. 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[p][q][r] can be computed as follows
Answer: B
Correct answer: &A[0][0][0] + w(y * z * p + z*q + r)
In row-major order the last index varies fastest. Moving one step in \(p\) skips a whole \(y \times z\) plane, one step in \(q\) skips a row of \(z\) elements, and one step in \(r\) skips a single element:
\[ \text{addr} = \&A[0][0][0] + w\,(y \cdot z \cdot p + z \cdot q + r) \]where \(w\) is the size of one element. The dimension \(x\) never appears, which rules out two of the options immediately - the number of planes does not affect where any one of them starts.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development