Example:
int a[99];
int (*p)[99] = &a;
// this prints 1
printf("%d\n", (void *) p == (void *) *p);
In general, if p
is a pointer to an array, then both the object representations (i.e. the bit patterns) of p
and *p
are equal.
I'm just lost and completely unsure about the portability of this behaviour.
So, I'm curious whether this behaviour is guaranteed by the Standard. If so, could someone please quote all of the relevant paragraphs that guarantee it?
This comparison is guaranteed to be 1.
The relevant part of the C standard is section 6.5.9p6 regarding the equality operator and the comparison of pointers:
Two pointers compare equal if and only if both are null pointers, both are pointers to the same object (including a pointer to an object and a subobject at its beginning) or function, both are pointers to one past the last element of the same array object, or one is a pointer to one past the end of one array object and the other is a pointer to the start of a different array object that happens to immediately follow the first array object in the address space.
Take particular note of the passage in bold. This means two things: 1) a pointer to a struct and a pointer to its first member (suitable converted) will compare equal, and 2) a pointer to an array and a pointer to its first member (again, suitable converted) will compare equal.
In your particular case, p
points to an array and *p
is the array itself, and using *p
in an expression yields a pointer to its first member. Both are converted to void *
to give them a common type. So this comparison will always evaluate to 1.