下列例子用到了C++的关键词 and, not,虽然这种作法比较少用,但它可读性比||
和!
会好不少。
bool isOk = false; int i = 1; if (i < 2 and i > 0) isOk = true; if (not isOk) { printf("OK"); }
能够在iso646.h
头文件中找到:微信
#define and && #define and_eq &= #define bitand & #define bitor | #define compl ~ #define not ! #define not_eq != #define or || #define or_eq |= #define xor ^ #define xor_eq ^=
&
或|
致使逻辑错误。if (x && y) { ... } /* 遗留了&可能致使程序意想不到的缺陷 */ if (x & y) { ... } /* 而遗留了and则直接致使编译错误,从而发现错误 */ if (x and y) { ... }
& | ^
等字符,须要使用关键词来标识。/Za
以支持替代关键字。更多精彩文章请关注微信公众号:「Qt君」code