I am slowly starting to really get a grasp on pointers, but I am quite confused on how the memory allocation of pointers is beneficial:
- On most compilers, a pointer is either 4 bytes or 8 bytes. In contrast to this, it is known that pointers, while taking up space in memory, take up much less space than the data types they point to. If this is the case, how can a pointer of size 4 or 8 bytes ever take up less space than the data type it points to (int - 4 bytes, char - 1 byte, etc.)?
(I understand that pointers are most useful when dealing with dynamic memory allocation, but I am just interested in the size of memory, not the use of that memory right now)
A pointer is a variable that contains a memory address. That is all it contains. It does not contain the data at the memory address that it represents, much like an address book doesn't contain all of the houses for which it stores addresses.