This answer presumes the C implementation uses a 32-bit int
and a 64-bit long
.
C 2018 6.4.4.1 says “The type of an integer constant is the first of the corresponding list in which its value can be represented.” In the table that follows, the entry for decimal constants with no suffix contains the list int
, long int
, long long int
. Since a long int
is the first of those that can represent 2,147,483,648, 2147483648
has the type long int
.
Per 6.5.3.3 3, the result of -
is the promoted type. The integer promotions (6.3.1.1 2) have no effect on long int
. So the type of -2147483648
is long int
.
Per 6.7.9 11, the value of the initializer is converted as in simple assignment. Per 6.5.16.1 2 and 6.5.16 3, the value is converted to the type of the object being assigned would have after lvalue conversion. That is, for an assignment to an int
object, the type is an int
value.
Per 6.3.1.3 1, when converting a value of integer type to another integer type, if the new type can represent the value, it is unchanged. Since int
can represent −2,147,483,648, it is unchanged.
Therefore, the result of int x = -2147483648;
is that x
is initialized with the value −2,147,483,648.
0
solved What happens when evaluating `int x = -2147483648`?