Thomas Ayoub Thomas Ayoub - 1 year ago 42
C++ Question

Should I use "&&" or "and"?

I'm using C++11 and both are compiling without any warning, witch one is the best way to do it?

if(a && b)


if(a and b)

Answer Source

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.

Can't paste table 2, but it explicitly states Alternative: and, Primary && (same for or and ||).

So they are absolutely identical. If you want to try and convince yourself one is "better" than the other, that's your business. If someone else is trying to argue such, they'd better have a good reason.

Edit: The aforementioned Table 2:

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

Edit: Maybe worth noting, according to Sebastian Redl, MS break the rules here.