Pointer equivalence for arrays in C: If the array arr begins at address 65486, what will printf output for these two expressions?\n#include<stdio.h>\n\nint main()\n{\n int arr[] = {12, 14, 15, 23, 45};\n printf("%u, %u\n", arr, &arr);\n return 0;\n}

Difficulty: Easy

Correct Answer: 65486, 65486

Explanation:


Introduction / Context:
This question clarifies the difference between the expressions arr and &arr in C, especially when printed as numeric addresses.



Given Data / Assumptions:

  • arr is a contiguous array of int and begins at address 65486.
  • We are printing with %u to visualize the underlying address values.


Concept / Approach:
In expressions, arr decays to a pointer to its first element, i.e., &arr[0]. The expression &arr is a pointer to the entire array type int (*)[5]. Both point to the same starting address in memory, even though their types and pointer arithmetic semantics differ. Therefore, when cast to an integer and printed, the numeric values are equal.



Step-by-Step Solution:
arr → &arr[0] → address 65486.&arr → address of the whole array object → also 65486.Printing both yields “65486, 65486”.



Verification / Alternative check:
Print (arr+1) and (&arr+1) to see different arithmetic: arr+1 advances by sizeof(int); &arr+1 advances by sizeof(arr).



Why Other Options Are Wrong:
They assume the addresses differ, which is false; the base address is identical though pointer types differ.



Common Pitfalls:
Confusing equal starting addresses with identical pointer types; using %u/%p incorrectly (formally, %p is the correct specifier for addresses).



Final Answer:
65486, 65486

More Questions from Arrays

Discussion & Comments

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