Cout <(1>-2) <endl; // 1 normal, all are signed numbers
Cout <(unsigned int) 1>-2) <endl; // 0-2 is converted to an unsigned number.
Cout <(unsigned int) 1>-2.) <endl; // 1 float does not have an unsigned number. Therefore, the unsigned number must be greater than the negative number of the float type!
///////////////////////////////
Html> http://www.52rd.com/Blog/Detail_RD.Blog_lentil_13982.html
The following experiments run in virual c ++ 6
To test whether the principle of automatic Integer Conversion in the C language is understood, some developers know very little about it. When the expression contains a signed or unsigned type, all operands are automatically converted to the unsigned type. Therefore, in this sense, the computing priority of the unsigned number is higher than that of the signed number, which is very important for embedded systems that should frequently use the unsigned data type.
First, conduct an experiment to define a signed int type data and an unsigned int type data respectively, and then compare the size:
Unsigned int a = 20;
Signed int B =-130;
A> B? Or B>? The experiment proves that B> a, that is,-130> 20, why is this result?
This is because in C language operations, if there is an operation between the unsigned number and the signed number, the compiler will automatically convert it to the unsigned number for processing. Therefore, a = 20, B = 4294967166. In this case, B>.
Another example:
Unsigned int a = 20;
Signed int B =-130;
Std: cout <a + B <std: endl;
The result output is 4294967186. Similarly, before calculation, a = 20 and B are converted to 4294967166, so a + B = 4294967186
Subtraction is similar to multiplication.
If B =-130 is used as the signed int data, the operation between B and the immediate number does not affect the type of B, and the operation result is still signed int:
Signed int B =-130;
Std: cout <B + 30 <std: endl;
The output is-100.
For floating point numbers, float (double) is actually a signed number. The unsigned and signed prefixes cannot be added to float and double, of course, there is no conversion problem between the unsigned numbers.