Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the letter L in long variable declaration

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.

like image 466
PSR Avatar asked Jul 19 '13 04:07

PSR


1 Answers

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:

  • Primitive Data Types, specifically Default Values and Literals sections.
like image 70
Luiggi Mendoza Avatar answered Sep 22 '22 04:09

Luiggi Mendoza