weight's Pointers

Why the first weighs 4 bytes while the second weighs 8 bytes??

int* p = new int(8);
cout << sizeof(p) << endl;
cout << sizeof(&p) << endl;
I wouldn't say weigh's..It's the size. A byte is 8 bits.

As far as the difference. One is the size of a pointer which is 4 bytes and the other is the size of an int (long in this case) which is 8 bytes. just realized that it was the address of the pointer and not the dereferencing the pointer. So the later is a pointer to a pointer as peter mentioned.


As for the size of a pointer I believe it is a word so on a 32 bit machine 4 bytes and on a 64 bit machine 8 bytes.
Last edited on
&p gives a pointer to the pointer p so both are actually the size of pointers.

I'm surprised that your compiler does not use the same size for all pointers (except function pointers). I guess it's allowed by the standard but I don't see any good reason for it. What compiler, and on what system, are you using?

Topic archived. No new replies allowed.