在长变量声明中使用字母L. [英] Using the letter L in long variable declaration
本文介绍了在长变量声明中使用字母L.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
long l2 = 32;
当我使用上述语句时,我没有收到错误(我没有使用 l
在最后),但是当我使用下面的语句时,我收到此错误:
When I use the above statement, I don't get an error (I did not used l
at the end), but when I use the below statement, I get this error:
int类型的文字3244444444超出范围
The literal 3244444444 of type int is out of range
long l2 = 3244444444;
如果我使用 long l2 = 3244444444l;
,那就没有错误。
If I use long l2 = 3244444444l;
, then there's no error.
这是什么原因?对于长变量,使用l不是强制性的。
What is the reason for this? Using l is not mandatory for long variables.
推荐答案
3244444444
被解释作为文字整数但不能适合32位 int
变量。它必须是文字长值,因此需要 l
或 L
at结束:
3244444444
is interpreted as a literal integer but can't fit in a 32-bit int
variable. It needs to be a literal long value, so it needs an l
or L
at the end:
long l2 = 3244444444l; // or 3244444444L
更多信息:
- 原始数据类型,特别是默认值和文字部分。
- Primitive Data Types, specifically Default Values and Literals sections.
这篇关于在长变量声明中使用字母L.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文