Not in this example. But sometimes it does, when values are close to the limit of what can be represented in 16 bits.
Here is another example:
short x = 12; short y = 3; short result; result = x / y;
The expression x / y
divides a
32-bit 12 by a 32-bit 3, even though the variables x
and y
are only 16 bits wide.
The answer then will be shortened to 16 bits and placed in
result.
At the professional programming level, details like these are sometimes important.
But mostly for general purpose programs use int
or
long
for integers and double
for floating point.
This will keep you out of trouble.
Do you expect that a modern electronic calculator will give you the same
answer as Java for the expression
(31.5 - 12)/4.1