Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Let the variable A be an integer, F be a real number and I be a double precision. What is the data type of the expression 10+'a'+i*f? Thank you.
Let the variable A be an integer, F be a real number and I be a double precision. What is the data type of the expression 10+'a'+i*f? Thank you.
The expression result is a double type.

In C language, if the types of operands involved are different, they are converted to the same type first, and then the operation is performed. Transform in the direction of increasing data length to ensure that the accuracy does not decrease.

Therefore, in the expression 10+'a'+i*f, when 10+'a', the character type of' a' will be automatically converted to integer type, and when i*f is operated, it will be automatically converted to double precision type,10+'a'.

Extended data:

Rules related to automatic type conversion:

1. 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.

2. 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, the accuracy will be reduced, and the lost part will be discarded directly.

3. When performing arithmetic operation, low type (short byte) can be converted into high type (long byte); For example, int type is converted into double type, char type is converted into int type and so on.

Baidu Encyclopedia-Forced Type Conversion