C++ Alternative Operator Representations

19 April, 2026 - #c++

C++ often gets written using the symbols &&, || and !.

Some languages, like Python, instead use and, or and not keywords for boolean operations. However, you can, in fact use them in C++ for boolean operators.

C++ allows us to rewrite our "traditional" boolean expressions equivalently using the keyword equivalents.

if (!a && b || (c && d))

is equivalent to

if (not a and b or (c and d))

Whether to use &&, || and ! or their equivalent and, or, and not is a stylistic choice.

That's super neat!

Why does this work?

These are examples of alternative operator representations, a historical holdover to support character encodings where characters for these operators didn't exist. While trigraphs were removed in C++17, alternative tokens are still available. In C, these are macros brought in by including <iso646.h>, but they are built-in keywords in C++. There are a few more than I've mentioned, but they can be used similarly.

You can use an alternative operator wherever its standard token equivalent can appear in source code. However, for alternative tokens like and, this means that you can use it to replace && when describing rvalue references.

Please don't confuse your coworkers like this:

// A less straightforward way to write "Peas&& Carrots" void foo(Peas and Carrots) { // ... }

You can also use these when declaring structs and classes if you choose. You can turn obsfucation up to 11 and get something like this:

struct Carrots <% compl Carrots(); // destructor // Copy assignment operator. Carrots bitand operator=(const Carrots bitand other) and; %>;

You can disguise important facts by being cute, like that foo here is only callable on const rvalues (since and replaces the && rvalue reference qualifier).

void foo() const and final;

Luckily, these are tokens not characters, so you can't get away with using them as a piece of another token.

if (a not = b) // Won't compile { c xor = b; // Won't compile }

The = equivalents have their own _eq prefix versions though. Curiously, there's no eq alternative.

if (a not_eq b) // a != b { c xor_eq b; // c ^= b; }

In short, C++ has alternative ways of writing a bunch of operators; this is a fun piece of C++ trivia and history that's still in the language.

The boolean keywords could be argued to improve readability, but the important thing is to always write in the clearest and most consistent way with the rest of your team.