Reputation: 41
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
unsigned int a =5;
unsigned int *pint = NULL;
cout << "&a = " << &a << endl;
cout << " &pint = " << &pint << endl;
}
Output:
&a = 0x6ffe04
&pint = 0x6ffdf8
I'm wondering why the address of pint
equals 0x6ffdf8
. pint
is an unsigned int
(4 bytes), shouldn't the address of it be 0x6ffe00
?
Upvotes: 3
Views: 238
Reputation: 26703
Your pint
is not an unsigned int. It is a pointer to an unsigned int.
Pointer can have a different size and can especially have the size 8.
It could hence fit into 0x6ffdfc before 0x6ffe04.
But it also has bigger alignment needs, it wants an address dividable by 8, so 0x...c
is out, it needs e.g. 0x...8
.
With 463035818_is_not_a_number I agree that this not really predictable, there are implementation specific aspects. That is why I phrase "softly" with "can", "wants", "e.g."....
Upvotes: 6