So I almost went all hurr durr on my classmates when they wrote that
&array
gives you address of the first element
But turns out they are right. This sounds like inconsistency to me. We're talking about array defined like this:
int numbers[] = {1,2,3,4};
The variable numbers
is (I think) then of type int* const
. I'd think that pointer to that would be int** const
. But apparently this expression evaluates as true:
if(&numbers == numbers) {
printf("Pointer to array is still the same array!\n");
}
And of course, this then also is true:
int* first_elm_ptr = &numbers;
if(*first_elm_ptr == *numbers)
printf("%d == %d\n", *first_elm_ptr, *numbers);
So apparently you cannot get a pointer to the variable holding address of that array. Expression &numbers
is essentially meaningless. Maybe it is even removed by compiler.
How's that possible? I am very confused right now! How does standard explain this behaviour? I made an ideone test code to verify this: http://ideone.com/pYffYx