gpt4 book ai didi

c++ - 我应该使用 "&&"还是 "and"?

转载 作者:IT老高 更新时间:2023-10-28 22:24:10 25 4
gpt4 key购买 nike

我正在使用 C++11 并且两者都在编译时没有任何警告,女巫是最好的方法吗?

if(a && b)

if(a and b)

最佳答案

2.6 Alternative tokens [lex.digraph]

1 Alternative token representations are provided for some operators and punctuators.16

2 In all respects of the language, each alternative token behaves the same, respectively, as its primary token, except for its spelling.17 The set of alternative tokens is defined in Table 2.

无法粘贴表 2,但它明确说明了替代方案:and、Primary &&(or| 相同) |).

所以它们是完全一样的。如果您想尝试说服自己一个比另一个“更好”,那是您的事。如果其他人试图这样争论,他们最好有充分的理由。

编辑:上述表2:

Table 2 — Alternative tokens
Alternative Primary
<% {
%> }
<: [
:> ]
%: #
%:%: ##
and &&
bitor |
or ||
xor ˆ
compl ~
bitand &
and_eq &=
or_eq |=
xor_eq ˆ=
not !
not_eq !=

编辑:也许值得注意,根据 Sebastian Redl ,MS在这里打破了规则。

关于c++ - 我应该使用 "&&"还是 "and"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17110294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com