In C, when printing the addresses of an array and its first element on a typical system conceptually viewed with 2-byte ints, suppose the array arr begins at address 1200. What values are printed for arr, &arr[0], and &arr using %u? #include<stdio.h> int main() { int arr[] = {2, 3, 4, 1, 6}; printf("%u, %u, %u ", arr, &arr[0], &arr); return 0; }

Difficulty: Easy

Correct Answer: 1200, 1200, 1200

Explanation:

Introduction / Context: This problem reinforces that an array name decays to the address of its first element in expressions, and that &arr gives the same numeric base address but has a different pointer type (pointer to the entire array).

Given Data / Assumptions:

  • arr starts at numeric address 1200.
  • arr is int arr[5] with conceptual 2-byte ints for address arithmetic context.
  • We print arr, &arr[0], and &arr using %u (just numeric addresses).

Concept / Approach: In C, arr (in most expressions) decays to &arr[0]. Therefore arr and &arr[0] point to the same location numerically. The expression &arr has type pointer-to-array-of-5-ints, but it still points to the same starting address numerically.

Step-by-Step Solution:

arr -> address of first element = 1200 &arr[0] -> also 1200 &arr -> address of whole array = same numeric base 1200

Verification / Alternative check: Dereferencing levels differ: *arr is int, while *&arr is the whole array. Yet the base numeric address stored is identical, so printing with %u shows 1200 for all three.

Why Other Options Are Wrong:

  • 1200, 1202, 1204 and 1200, 1204, 1208: Assume increments without actually incrementing pointers.
  • 1200, 1202, 1200: Invents a 2-byte offset for &arr[0] even though no arithmetic was done.

Common Pitfalls: Confusing pointer type with numeric address value. Type affects arithmetic step size, not the base numeric address printed here.

Final Answer: 1200, 1200, 1200

Discussion & Comments

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