The result of an int type and double type operation is double type
.
This is because when an operation involves both an int and a double, the int is automatically converted to a double before the operation takes place. This is called type promotion.
For example, if we have the following code:
int num1 = 5; double num2 = 2.5; double result = num1 + num2;
In this case, the int value of 5 is automatically promoted to a double before the addition operation takes place. The result of the addition is also a double, which is then assigned to the variable result.
So even though one of the operands was an int, the final result is a double due to type promotion
原文地址: https://www.cveoy.top/t/topic/g0nv 著作权归作者所有。请勿转载和采集!