If multiple types of variables and constants (mixed types) are used for the same statement or expression, C automatically converts them to the same type. The following are the basic rules for automatic type conversion:
1. In an expression, values of the char and short types, whether signed or unsigned, are automatically converted to int or unsigned.
INT (if the short size is the same as the int size, the unsigned short value range is greater than the int value. In this case, unsigned
Short is converted to unsigned INT ). Because they are converted to a type with a larger range, they are called "Upgrade )".
2. Sort data types in the order from high to low, which are long Double, double, float, and unsigned in sequence.
Long long, long, unsigned long, long, unsigned int and
Int. Here is a small exception. If long and INT are the same size, the unsigned int level should be above long. Char and
Short does not appear in this level list because it should have been upgraded to int or unsigned Int.
3. In any operation that involves two data types, lower-level types between them will be converted to higher-level types.
4. In the value assignment statement, = the value on the right is assigned =
Before the left variable, you must first convert the Data Type of the right value to the left variable type. That is to say, what data type is the variable on the left, and what data type is the value on the right. This process can be
It can upgrade the type of the value on the right or degrade the type ). The so-called "downgrade" refers to the conversion of a type with a higher level to a type with a lower level.
5. When passed as a parameter to a function, char and short will be converted to int, and float will be converted to double. The function prototype can be used to avoid this automatic upgrade.
32-bit Server
Int 4-2 ^ 31 ~~ (2 ^ 31-1)
Unsigned int 4 0 ~~ (2 ^ 32-1)