【发布时间】:2017-06-06 04:29:14
【问题描述】:
我看到and 关键字在if 语句中使用,就像&& 运算符一样。
这些(and,&&)之间有什么区别吗?
#include <iostream>
using namespace std;
int main()
{
bool a = true;
bool b = true;
if(a==true and b==true) // if(a==true && b == true)
{
cout << "YES ";
}
return 0;
}
【问题讨论】:
-
你确定有人不只是做
#define and &&吗? -
P.S.使用
a==true或a==false总是不好的形式,改用a或!a。规范的 C 或 C++ 将是if (a && b)。 -
我没有那样做。我已经编辑了我的问题。请看完整代码
-
@MarkRansom
a == true确实很糟糕,但我认为更详细但更明确的true == a或nullptr == ptr没有问题。
标签: c++