Difficulty: Hard
Correct Answer: ((((a+i)+j)+k)+l)
Explanation:
Introduction / Context:
In C, multi-dimensional arrays are arrays of arrays laid out contiguously in row-major order. Subscript notation a[i][j][k][l] can be expressed using pointer arithmetic and dereferencing. This question checks your understanding of how nested dereferences correspond to each subscript level.
Given Data / Assumptions:
Concept / Approach:
For an array T a[A][B][C][D], the expression a+i advances i elements of type T[B][C][D]. Dereferencing once with * yields a[i], which is of type T[B][C][D]. Repeating this logic, each subsequent + index and * dereference steps into the next dimension until reaching the scalar element T at [i][j][k][l].
Step-by-Step Solution:
Start: a+i → pointer to a[i] (type: array of [B][C][D]).Dereference: (a+i) → a[i].Add j: (a+i)+j → &a[i][j] (pointer to array [C][D]).Dereference: ((a+i)+j) → a[i][j].Add k: ((a+i)+j)+k → &a[i][j][k] (pointer to array [D]).Dereference: (((a+i)+j)+k) → a[i][j][k].Add l: (((a+i)+j)+k)+l → &a[i][j][k][l].Final dereference: ((((a+i)+j)+k)+l) → a[i][j][k][l].
Verification / Alternative check:
For a 2D case a[i][j], the equivalent (a[i] + j) generalizes to higher dimensions by nesting the pattern consistently, confirming the chosen expression.
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting that each dimension requires a dereference before adding the next index; otherwise, types do not line up and the expression becomes ill-formed.
Final Answer:
(((*(a+i)+j)+k)+l).
Discussion & Comments