CKTIS / C++
true — Boolean truth literal
`true` is a C++ keyword and a literal of type `bool` representing truth. It is not the integer literal `1`, although promotion to `int` produces `1`. One common use is initializing Boolean variables.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
truetrue represents truth and has type bool. Together with false, it forms the pair of Boolean literals in C++. The statement bool enabled = true; initializes the variable enabled to true. Using the literal itself requires no header.
Distinguish value from type: true is a literal of type bool, whereas 1 is a literal of type int. When bool is promoted to int, true becomes 1 and false becomes 0. In the other direction, converting a numeric value to bool produces false for zero and true for every nonzero value, including negative values. Consequently, bool fromNumber = 7; stores true, not the number 7.
The example prints 1 1: enabled receives true directly, while fromNumber receives it through conversion of a nonzero number. The explicit static_cast<int> conversions match both arguments to the %d format. This entry targets C++23; the supplied reference points to an evolving standard draft, not a frozen C++23 edition. A repository compiler flag does not attest operation in a production runtime.
Examples
#include <cstdio>
int main() {
bool enabled = true;
bool fromNumber = 7;
std::printf("%d %d\n", static_cast<int>(enabled),
static_cast<int>(fromNumber));
}
Result
1 1
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.