Difficulty: Medium
Correct Answer: 1002, 1002, 1002, 1
Explanation:
Introduction / Context:
This question checks your understanding of how multidimensional arrays decay to pointers in C, what a
, *a
, and **a
mean for a 3-D array, and how dereferencing down to **a
yields the first stored integer. The addresses are based on a provided base location (1002).
Given Data / Assumptions:
%u
for printing pointer values (strictly, standard requires %p
, but we follow the problem’s convention).
Concept / Approach:
For int a[2][3][4], the identifiers behave as follows: a → pointer to first element, type int ()[3][4], value &a[0]a → the first element, type int [3][4]; when passed to printf, it decays to &a[0][0] (type int ()[4])*a → the first row inside that, type int [4]; it decays to &a[0][0][0] (type int)***a → the first scalar int value stored, which is 1 from the initializerAll three pointers point to the same starting address of the entire object’s first scalar element.
Step-by-Step Solution:
a → &a[0] → address 1002*a → a[0] → decays to &a[0][0] → address 1002**a → a[0][0] → decays to &a[0][0][0] → address 1002***a → a[0][0][0] → integer value 1
Verification / Alternative check:
Manually expand indices: a == &a[0]*a == a[0] and &a[0][0] is where the first 4-int row begins**a == a[0][0] and &a[0][0][0] is the first scalar
Why Other Options Are Wrong:
(a) and (b) assume incorrect scaling to different addresses; all three decayed pointers start at the same base. (d) No compile-time error for this code. (e) The problem pins the base address; under those assumptions, the triplet is not variable.
Common Pitfalls:
Confusing types of a
, *a
, and **a
; assuming each must advance to a different address; or thinking ***a
is a pointer rather than a scalar.
Final Answer:
1002, 1002, 1002, 1
Discussion & Comments