Will an int be 32bit and a long 64bit regardless of whether the system is 32 or 64 bit?

拥有回忆 提交于 2019-12-10 15:12:35

问题


In java, is an int guaranteed to always be of 32bit size and a long of 64bit size regardless of whether the architecture is 32 or 64 bit?


回答1:


Java is platform independent. So int is 32-bits, and long is 64-bit.




回答2:


The Java Tutorial page on primitive data types specifies the fixed sizes and makes no mention of underlying architecture having any influence

int: The int data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive).

long: The long data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). Use this data type when you need a range of values wider than those provided by int.




回答3:


int in Java is always 32-bit. No matter the OS type/architecture/whatever.



来源:https://stackoverflow.com/questions/18017752/will-an-int-be-32bit-and-a-long-64bit-regardless-of-whether-the-system-is-32-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!