It seems that the compiler pushed certain objects on the stack as follows
So &ptr is the address where ptr is distributed. &ptr + 1 is the next address after ptr and at the same time it is address [0].
Note that it is unspecified in what order the compiler should push local variables onto the stack.
It also seems that in the environment where the sizeof( int * ) program was compiled, which corresponds to sizeof( *( &ptr + 1 ) ) , it is equal to sizeof( int ) and, in turn, is 4. Or sizeof( int * ) is 8, but sizeof( int ) is 4. Because you use the %d format specifier in printf to express *( &ptr + 1 ) , then exactly [0] is output.
By the way, you can check if this scheme matches the actual placement of variables by printing
printf("(&ptr + 1) = %p\n", &ptr + 1 ); printf("(&a[0]) = %p\n", &a[0] );
If the addresses are not equal, then this means that there is some arbitrary value at the address &ptr + 1 , which does not correspond to [0].
Regarding the question in the header of your message
The difference between * ptr and * (& ptr + 1)
then *ptr matches a[0] , while the expression *(&ptr + 1) leads to undefined behavior because you are trying to dereference the address after ptr.
source share