Because a pointer contains a memory address, and all memory addresses are the same size.
For example, imagine that the computer’s memory looks like a street with several houses side by side, numbered as 0, 1, 2, 3... (and yes, they start at zero). Each of these houses stores a byte in memory. Also, you can refer to each of these houses by their address. To represent the address of one of these houses, just the number of the house, after all, there is only one street in this case.
If you are on a 32-bit (32-bit = 4-byte) architecture, then the last street house would be the 4,294,967,295 number, which corresponds to 232 - 1. This is the same as 4 Gb. Therefore, to represent any memory address (memory up to 4 Gb), you will need addresses with 4 bytes.
Finally, note that no matter what type of data you store in these houses, you still need the same number of bytes to represent an address. A pointer to float
nothing is more than somewhere in the memory of where you want to read or write a float
, and a pointer to int
is a place where you want to read or write a int
. Regardless of what you want to read or write, the referenced houses are the same and are on the same street, and therefore have addresses of the same type.
4 Gb of memory at most is insufficient for modern computers. Therefore, on 64-bit architectures, addresses have 8 bytes. That’s theoretically enough for 8 exbibytes. But obviously, in practice, there are no computers with that much memory and we are very far from having them. However, if you need anything with more than 4 Gb of memory, the 64-bit architecture is virtually mandatory.
32-bit machine has 32-bit pointers. 64-bit machine has 64-bit pointers. 16-bit machines (or PIC controllers) have 16-bit pointers. Independent of the pointed type
– Jefferson Quesado
There are contexts in which
int
is 16 bits, mainly for controllers and for older machines. As rare as these contexts are, they exist– Jefferson Quesado