The int
s are not promoted to long long
before multiplication, they remain int
s and the product as well. Then the product is cast to long long
, but too late, overflow has struck.
Having one of a
or b
long long
should work as well, as the other would be promoted.