smaller
is an int
, so is the literal 2
. So their product is an int
too. Since INT_MAX * 2
can't be represented by an int
(by definition, pretty much), it overflows leading to undefined behavior.
If, however, you store the value in a long long
, then, when performing the multiplication, default integer promotion (the "usual arithmetic conversion") happens. Now, if your long long
can represent INT_MAX * 2
, you will end up with something semantically equivalent with bigger = bigger * (long long)2
, which works as expected.