In C, array subscripting x[y] is defined as *(x + y). Using this property, what does the expression 0[arr] print for an array declared as int arr[1] = {10}? #include<stdio.h> int main() { int arr[1] = {10}; printf("%d ", 0[arr]); return 0; }

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:

  • arr is int arr[1] initialized to {10}.
  • We evaluate 0[arr].

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:

arr[0] == *(arr + 0) 0[arr] == *(0 + arr) == *(arr + 0) *(arr + 0) is the first element value, which is 10

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:

  • 1 and 0: Confuse value with indices.
  • 6: Arbitrary number not present in the array.

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

More Questions from Arrays

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion