Why does short s = 1 not report an error?

1 is int type, why short s = 1 does not report an error, while 1.1 is double type float f = 1.1 ?

Mar.28,2021

because if the int exceeds the short range, the lower part will be truncated, and if the value is not exceeded, it will be assigned normally.

but the double type is unpredictable, and perhaps very simple numbers are full of bytes, such as 0.5, which is actually expressed in memory as: 0.499999999999
. This is obviously not allowed. So the float assignment decimal must be marked so that the editor can check it during compilation.

Menu