Difficulty: Easy
Correct Answer: 10
Explanation:
Introduction / Context:
This question highlights that in C the expression x[y] is syntactic sugar for *(x + y), which is commutative in terms of numeric addition, so y[x] is equivalent to x[y].
Given Data / Assumptions:
Concept / Approach:
Since x[y] == *(x + y) == *(y + x), we can swap the operands in the subscript without changing the result as long as the sum points to a valid element.
Step-by-Step Solution:
Verification / Alternative check:
Compile-and-run thought experiment: replacing 0[arr] with arr[0] preserves meaning; both select the first element.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming x[y] must be “array name then index” by syntax rules. In C, addition is commutative, so y[x] is equally valid for access (though unconventional to read).
Final Answer:
10
Discussion & Comments