Why is that the following code will compile and execute but will yield a wrong result due to integer overflow?
int r = 0;
long x = 1_000_000_000_000l;
r += x;
While this one will generate a compiler error incompatible types: possible lossy conversion from long to int
.
int r = 0;
long x = 1_000_000_000_000l;
r = r + x;