Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C++

bitand — alternative spelling of &

`bitand` is a reserved alternative spelling of the `&` token in C++. It therefore means more than bitwise AND: depending on context, it can also take an address or declare an lvalue reference.

Version: C++23; repository compiler flag, production runtime not attested

Syntax

lhs bitand rhs
bitand object
T bitand ref = object;

bitand is a C++ alternative token corresponding to &. It has the same meaning as & in its context; its spelling differs and is preserved by operations such as stringizing a macro argument. It needs no header or macro definition and cannot be used as a user-defined identifier.

In lhs bitand rhs, the built-in operator performs bitwise AND: a result bit is 1 only when both corresponding operand bits are 1. Operands must have integral or unscoped enumeration types; the usual arithmetic conversions apply. Do not confuse bitand with and, which corresponds to &&: bitwise AND does not provide short-circuit evaluation. When combining it with a comparison, use parentheses, for example (value bitand mask) != 0.

The equivalence is not limited to bitwise AND. bitand object can take an address just like &object, and T bitand ref = object; declares an lvalue reference just like T& ref = object;. In the example, 1100 AND 1010 gives 1000, or 8. Assignment through ref then changes copy to 9, which is read through *ptr.

This entry targets C++23. The supplied source is an evolving working draft, not a frozen C++23 publication. The displayed source was run unchanged in an isolated environment, and its standard output (stdout) matched the stated output exactly. This does not attest a production runtime.

Examples

#include <iostream>

int main() {
    constexpr unsigned value = 0b1100u;
    constexpr unsigned mask = 0b1010u;
    constexpr unsigned result = value bitand mask;
    static_assert(result == 8u);

    unsigned copy = result;
    unsigned bitand ref = copy;
    unsigned* ptr = bitand copy;
    ref = 9u;

    std::cout << result << ' ' << *ptr << '\n';
}

Result

8 9

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources