2147483647 + 1
is evaluated as the sum of two ints
and therefore overflows.
2147483648
is too big to fit in an int
and is therefore assumed by the compiler to be a long
(or a long long
in MSVC). It therefore does not overflow.
To perform the summation as a long long
use the appropriate constant suffix, i.e.
a = 2147483647LL + 1;