In C language, if the operands on both sides of an operator are different, it is necessary to convert them to the same type first, that is, to convert the lower-level type to the higher-level type, and then to participate in the operation. The conversion rules are as follows: float (floating point type) should be converted into double (double precision floating point type), int (integer) should be converted into unsigned (unsigned integer), and long (long integer) should be converted into double precision floating point type.
Therefore, the mixed operation of integer and floating point in C language can only be converted into the same double type (double precision floating point type) at the same time. If two floating-point numbers participate in the operation, although they are of the same type, they still need to be converted into double before the operation, and the result is also double.
Extended data:
In C language, automatic type conversion follows the following rules:
1. If the operands involved are of different types, first convert them to the same type, and then perform the operation.
2. Transform in the direction of increasing the data length to ensure that the accuracy does not decrease. Such as int and long operations, the int quantity is converted into long before the operation. If the number of bytes of the two types is different, it is converted to the type with higher number of bytes. If two types have the same number of bytes and one is signed and the other is unsigned, they are converted to unsigned types.
3. All floating-point operations are performed with double precision. Even expressions that only contain floating-point single-precision operations should be converted to double-precision types before operations.
4. When 4.char type and short type participate in the operation, they must be converted into int type first.
5. In the assignment operation, when the data types of the quantities on both sides of the assignment number are different, the type of the quantity on the right side of the assignment number will be converted into the type of the quantity on the left. If the data type length of the right quantity is longer than that of the left quantity, some data will be lost, which will reduce the accuracy, and the lost part will be rounded forward.
Baidu Encyclopedia -C language type forced conversion
Baidu Encyclopedia-Automatic Type Conversion