I know that pointers store the address of the value that they point to, but if you display the value of a pointer directly to the screen, you get a hexadecimal number. If the number is exactly what the pointer stores, then when saying
pA = pB; //both are pointers
you're copying the address. Then wouldn't there be a bigger overhead to using pointers when working with very small items like int
s and bool
s?
A pointer is essentially just a number. It stores the address in RAM where the data is. The pointer itself is pretty small (probably the same size as an int
on 32 bit architectures, long
on 64 bit).
You are correct though that an int *
would not save any space when working with int
s. But that is not the point (no pun intended). Pointers are there so you can have references to things, not just use the things themselves.