C ++ unsigned type operation object participation in type conversion

  When the operation object type of an operator is inconsistent, and one of the operation objects is an unsigned type, this type conversion needs to be performed accordingly. As for the result of the type conversion, it depends on the relative size of each integer type in the machine.
  
  When the operation object type of an operator is inconsistent, and one of the operation objects is unsigned, it is divided into the following situations:
  
  When the operation object of the unsigned type is larger than the operation object of the signed type, it will be signed After the type is converted to the corresponding unsigned type, the operation is performed. For the conversion rules, see the conversion of signed types to unsigned types in my blog C ++.
  
  When the operation object of the signed type is larger than the operation object of the unsigned type, the situation will be slightly more complicated Some:
  
  1. If the value range of the unsigned type in the machine is within the value range of the signed type, then convert the object of the unsigned type to the signed type for operation;
  
  2. If the machine The value range that the unsigned type can represent exceeds the value range of this signed type, and then the object of the signed type must be converted to the unsigned type for operation.
  
  Again, do n’t mix signed and unsigned types, because mixing signed and unsigned types often leads to results that are very different from our expectations.

Guess you like

Origin www.cnblogs.com/zhenhua1618/p/12729626.html
Recommended