Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

true — Boolean constant in C23

In C23, true is a keyword representing a constant of type bool with value 1. It does not require the <stdbool.h> header.

Version: C23; repository compiler flag, production runtime not attested

Syntax

true

In C23, true is a keyword representing a predefined constant of type bool with value 1. Its counterpart, false, has value 0. The <stdbool.h> header is not needed to use these keywords.

Use true to initialize flags, for example bool ready = true;. Do not equate type bool with type int: promotion to int occurs only in contexts that apply the integer promotions. For example, typeof(true) yields bool, and initializing a bool with true does not promote true to int.

In the example, ready is promoted to int when passed to printf, so %d prints 1. The example requires C23 support; the expected result does not imply that testing has been performed.

Examples

#include <stdio.h>

int main(void)
{
    bool ready = true;
    printf("%d\n", ready);
    return 0;
}

Result

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.

Sources