-
C arrays
Hi guys , i confused with arrays ...
see this foll code
<code>
int arr [3];
printf("%u %u",arr,&arr);
</code>
i get the same address for arr and &arr .
Does this mean & operator is defined in such a way or that there is something to do with arrays , if so what is that .
Thanks guys.
-
What address do you think it should show?
-
Yes, this is a quirk of arrays.
arr is the address of the first element. &arr is the address of the array, the array starts at the first element, so you'll see &arr == arr.
QuantumPete
-
Since arrays as arguments to functions are translated to the address of the first element, then I would expect that the address of an array is the same as the address of the first element, numerically. They are not the same semantically, as the address of the first element is a pointer of the type of the array (int *), whilst the address of the array is a pointer to array int [3]. But the address of the two would be the same.
--
Mats
-
Note that you print addresses with %p (and typically cast to void*, as well).