What would be the size of int and int* on a Linux 64-bit environment? I expect both to be same but am getting different sizes… need some explanation!
-Sumit Maurya
Incidentally, I recently posted an article on our blog about sizes of integral types, with a link posted on our facebook page.
To clarify, the size of int
is dependent on the compiler, and is supposed to match the machine word size. The size of that is assumed by the compiler. Compilers may give 4 bytes for int
, because long
can be 8 bytes wide – it is purely a decision of the compiler vendor!
The size of int*
, however, cannot be purely the choice of the vendor. Pointers are addresses, and given the fact that it is a 64-bit environment, addresses have to be 64-bits wide. Thus, the size of int*
(or any pointer) will be 8 bytes.
Related Questions:
Q: What exactly does a 64-bit environment mean? What is the meaning of the machine word size?
Q: Is it necessary that a 64-bit processor support a 64-bit address bus and a 64-bit data bus?
Q: Are the sizes of all pointers the same?
Related Articles
No user responded in this post