Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - int I =-20; Unsigned j =10; What is the value of i+j? Why?
int I =-20; Unsigned j =10; What is the value of i+j? Why?
-10, the type will be implicitly converted during the operation, and the low type will be converted to the high type. For example, when floating point numbers of float and double types are operated, the float type will be automatically converted to double type, and then the operation will be performed. The results are also of high type.

Type is actually the coverage of scope, which is related to the word length of CPU and compiler. Unsigned is lower than int in Linux_32-bit system. But remember that this is not certain, maybe it is not defined in winTC (I have never tried it).

Implicit conversion rules are as follows:

1. When the program performs arithmetic operations, the low-order type can be converted to the high-order type.

2. In the assignment expression, the value of the right expression is automatically implicitly converted to the type of the left variable and assigned to him.

3. When the function is called, the real parameter value is assigned to the parameter, and the system implicitly converts the real parameter into the type of the parameter and assigns it to the parameter.

4. When the function has a return value, the system will automatically convert the return expression type into the function type and assign it to the calling function.

PS: Implicit type conversion is confusing. The same code may have different results in different environments. If the program runs wrong because of this problem, it will be extremely difficult to find it. Therefore, the most reliable method is always to explicitly perform type conversion in the program.