The rules of integer constant in C is that an decimal integer constant has the first type in which it can be represented to in: int
, long
, long long
.
2147483648
does not fit into an int
into your system (as the maximum int
in your system is 2147483647
) so its type is a long
(or a long long
depending on your system). So you are computing sizeof (long)
(or sizeof (long long)
depending on your system).
2147483647
is an int
in your system and if you add 1
to an int
it is still an int
. So you are computing sizeof (int)
.
Note that sizeof(2147483647+1)
invokes undefined behavior in your system as INT_MAX + 1
overflows and signed integer overflows is undefined behavior in C.
Note that while generally 2147483647+1
invokes undefined behavior in your system (INT_MAX + 1
overflows and signed integer overflows is undefined behavior in C), sizeof(2147483647+1)
does not invoke undefined behavior as the operand of sizeof
in this case is not evaluated.