Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

long l2 = 32;

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:

The literal 3244444444 of type int is out of range

long l2 = 3244444444;

If I use long l2 = 3244444444l;, then there's no error.

What is the reason for this? Using l is not mandatory for long variables.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
157 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

More info:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...