C++ type conversion

Type conversion:
1. When we assign a non-Boolean arithmetic value to a Boolean type, the initial value is 0 and the result is false, otherwise the result is true.
2. When we assign a boolean value to a non-boolean type, the initial value is false, the result is 0, and the initial value is true, the result is 1.
3. When we assign a floating-point number to an integer type, an approximation is performed. The resulting value will retain only the part before the decimal in the floating point number.
4. When we assign an integer value to a floating-point type, the fractional part is recorded as 0. If the space occupied by the integer exceeds the capacity of the floating-point type, precision may be lost.
5. When we assign an unsigned type a value beyond its representation range, the result is the remainder after the initial value modulo the total number of values ​​represented by the unsigned type;
converting a negative number to an unsigned number is similar to directly assigning an unsigned number A negative value, the result is equal to the negative number plus the modulus of the unsigned number (for example, when -1 is assigned to an unsigned int, the result is 4294967295);
when there is both a signed type and an unsigned type in the expression, when the signed type is used. Negative values ​​produce unexpected results because signed numbers are automatically converted to unsigned numbers.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325100886&siteId=291194637