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.
sizeofreturns asize_t. When you callprintf("%d", ...you print it as anint. You should useprintf("%zu", ...or simply cast the result ofsizeoftoint.%zuis the format one should use for printing values of typesize_t. More description can be found at stackoverflow.com/a/5943869/139746 . I am not putting this as an answer because it won't solve the unrelated 4/8 issue that the question really is about. If the compiler does not support%zu, then workarounds areprintf("%d",(int)sizeof(...orprintf("%lu",(unsigned long)sizeof(...