【发布时间】:2017-11-08 08:35:27
【问题描述】:
我在浏览 cppreference 时看到了alternative operators(如and、or、not 等)。
它们是 &&、||、! 等“普通”运算符的替代品。
我检查了使用&& 和and 的代码的程序集。两个版本都生成了相同的程序集。
代码:
#include <iostream>
int n = 1;
int main()
{
// if(n > 0 && n < 5)
if(n > 0 and n < 5)
{
std::cout << "n is small and positive\n";
}
}
所以我的问题是:
-
&&和and运算符有什么区别? - 我应该在何时何地使用
and而不是&&? - 如果没有区别,那为什么 C++ 会引入替代运算符(如
and、or、not等)?
【问题讨论】:
-
没有区别。
and运算符只是&&的替代别名。 -
@YSC - 有点隐藏timsong-cpp.github.io/cppwp/n4659/lex.key#2
-
@StoryTeller 你可能是对的 - 我不是反对者,但我可以想象有人会这样看......
-
我认为反对票是早期反馈。这些天在这个网站上很常见。
-
@YSC 映射在timsong-cpp.github.io/cppwp/n4659/lex.digraph中明确给出
标签: c++ logical-operators