The "problem" here is results depending on the compile architecture.
Basic types in C (like e.g. int
, double
, char
) do not have a predefined size; it is up to the compiler which size to use for which type.
As for pointers, you typically want to be able to address any memory location available on your machine.
On 32 bit architectures, the address range is 2^32. As a pointer is nothing more than a number referring to the address the memory is located at, 2^32 addresses (i.e., a range of 4 Bytes) suits just fine.
For 64 bit systems, in order to address all memory, a range of 2^64 (i.e. 8 bytes) is necessary.
Therefor, pointer sizes need to depend on the system architecture.
Keep in mind: all pointer types (be it int*, char*, double*
or whatever) have the same size! Using integers and integer pointers on 32 bit can therefor be a bit confusing, as an int
has a size of 4 bytes on most architectures, as well.