Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C++

not — alternative spelling of logical negation

`not` is an alternative spelling of the `!` operator in C++. The built-in operator reverses its operand's truth value and returns `bool`. It is neither bitwise negation nor a separate library function.

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

Syntax

not expression
not (expression)

not denotes the same operator as !; it differs in spelling, not behavior. It is part of the language and requires no header. Place it before one operand, for example not ready or not (count == 0).

The built-in operator contextually converts its operand to bool, then returns true if the operand is false, or false if it is true. For integers, zero is false and nonzero values are true. The built-in operator's result has type bool. For a class type, an overload of operator! may be selected; the spelling not uses the same mechanism.

Watch grouping: not count == 0 means (not count) == 0, not not (count == 0). Use parentheses when you intend to negate a whole comparison. Do not confuse logical negation with bitwise negation ~, whose alternative spelling is compl.

The example demonstrates both operator spellings and negation of an integer and a comparison. This entry targets C++23; the supplied source is an evolving draft, not a frozen C++23 publication. It does not attest to the production runtime.

Examples

#include <iostream>

int main() {
    constexpr bool ready = false;
    constexpr int count = 0;

    static_assert((not ready) == (!ready));
    static_assert(not count);

    std::cout << std::boolalpha;
    std::cout << (not ready) << '\n';
    std::cout << (not count) << '\n';
    std::cout << (not (count == 0)) << '\n';
}

Result

true
true
false

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