Comparison between float X and zero:
If (x <0.000001 & x>-0.000001)
Note: floating point numbers cannot be directly compared to the size. Because they are not precisely stored, only one precision can be set (0.000001 indicates that the accuracy of the error is allowed ), then, the values within the allowable error are considered to be equal. It is incorrect to use = when comparing the floating point number.
Comparison between int X and zero:
If (X = 0) if (X! = 0)
Comparison between the pointer char * p and zero value:
If (NULL = p) if (NULL! = P)
Note: incorrect syntax
- If (p = 0) // It is easy to misunderstand that p is an integer variable.
- If (p! = 0)
- If (p) // It is easy to misunderstand that p is a bool variable.
- If (! P)
Comparison of bool flat and zero value:
If (flag) if (! Flag)
Note: Based on the Boolean semantics, the zero value is "FALSE" (as FALSE), and any non-zero value is "TRUE" (as TRUE ). There is no uniform standard for the TRUE value. For example, Visual C ++ defines TRUE as 1, while Visual Basic defines TRUE as-1. Therefore, we cannot directly compare a Boolean variable with TRUE, FALSE, or 1 or 0.