long val = 5000000000;
The error during this assignment is:
The literal 5000000000 of type int is out of range
Why does the compiler by default assume the literal to be type int
when it is declared with type long
?
You can use:
long val = 5000000000L;
Check it here
There is aspecific suffixes for long i.e L
. If there is no suffix, then 5000000000 assumed to be an int
type. And 5000000000 is out of int
range, causing the erro. So you need to add L
at the end of 5000000000 for it to be treated as a long
value. Change your declaration from
long val = 5000000000;
to
long val = 5000000000L;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With