why a + 1L in last line does not yield long integer as 4294967296 ?
Because converting the int
-1 to a long int
results in the long int
with value -1, and -1 + 1 = 0
.
Converting -1
to another type would only result in 4294967295
if the target type is an unsigned 32-bit type (usually, unsigned int
is such, generally, uint32_t
, if provided). But then, adding 1 to the value would wrap to 0.
Thus to obtain 4294967296
, you would need an intermediate cast,
(uint32_t)a + 1L
so that -1
is first converted to the uint32_t
with value 4294967295
, and that is then converted to long
.