Compiling environment: Ubuntu 12.04: gccwindows XP: VS-2005
Let's take a deeper look at the condition in the IF (condition) statement, that is, when the condition is true and when it is false.
The main body of the test code is as follows:
int main(int argc, char *argv[]){if (CONDITION)printf("true.\r\n");elseprintf("false.\r\n");return 0;}
Situation 1:
Condition:
(1)/* true */
(0)/* false */
(-1)/* true */
Conclusion: 0 is false, and non-zero is true.
Situation 2:
Signed int value1 = 11;
Signed int value2 = 328;
Condition:
(Value1-value2)/* true-3rd cases in the same [scenario 1 */
(Value1-value2)> 2000)/* false */
Situation 3:
Unsigned int value1 = 11;
Unsigned int value2= 328;
Condition:
(Value1-value2)/* true-3rd cases in the same [scenario 1 */
(Value1-value2)> 2000)/* true */
This involves the"
Implicit conversion(Value1-value2) is implicitly converted to the unsigned int type. The conversion method is the complement code of (value1-value2 ).
(Value2-value1)> 2000)/* false */
Situation 4:
Int value1 = 11;
Unsigned int value2= 328;
The result is the same as situation 3.
Implicit conversions of data types. If one of the operands is an unsigned int, the other operand is also considered as an unsigned Int.
(Value1-value2)/* true */
(Value1-value2)> 2000)/* true */