-
And: && (about two expressions are true only for true)
-
Or: || (about at least one of the two expressions is true only for true)
-
non:! (Equivalent to negate, to really make false non-operational, non-operational for false do is true)
-
int m = 20; int n = 30; if (m == 20 && n == 30) { cout << "m == 10 , n == 30" << endl; } if (m == 20 || n == 40) { cout << "两个表达式至少一个为真" << endl; } if (!(m < 20)) { cout << "!(m < 20)" << endl; } /*结果: m == 10 , n == 30 两个表达式至少一个为真 !(m < 20) */
-
Short-circuit problem
- Mainly for logic and logical or
- For a logical and &&: if the first expression is detected is false, then the rest of the expression will not be checked.
- For a logical or ||: if the detected first expression is true, then the rest of the expression does not check.
-
By short-circuiting problem to determine whether the function of a class is initialized, it is empty
MyClass *myClass; ... //myClass.process() if(myClass != NULL && myClass.process()) { ... }