They originated in C in the header <iso646.h>
. At the time there were keyboards that couldn't type the required symbols for &&
(for example), so the header contained #define
's that would assist them in doing so, by (in our example) defining and
to be &&
. Of course, as time went by this became less used.
In C++, they became what are known as alternate tokens. You do not need to include anything to use these tokens in a compliant compiler (as such, the C++-ified version of the C header, <ciso646>
, is blank). Alternate tokens are just like regular tokens, except for spelling. So during parsing and
is exactly the same as &&
, it's just a different way of spelling the same thing.
As for their use: because they are rarely used, using them is often more surprising and confusing than it is helpful. I'm sure if it were normal, they would be much easier to read, but people are so used to &&
and ||
anything else just gets distracting.
EDIT: I have seen a very slight increase in their usage since I posted this, however. I still avoid them.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…