Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

stdbool.h — Boolean values header

In C23, bool, true, and false belong to the language. The <stdbool.h> header remains available but is not needed to use them.

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

Syntax

#include <stdbool.h>

Include <stdbool.h> with #include <stdbool.h>. In C23, bool, true, and false are keywords, not macros supplied by this header.

According to N3096, §7.19, the header provides __bool_true_false_are_defined, a macro expanding to 1. This macro is obsolescent; avoid relying on it in new code.

Converting a number to bool produces false for zero and true for a nonzero value. The example demonstrates this normalization; the casts to int allow printing the values with %d.

Examples

#include <stdbool.h>
#include <stdio.h>

int main(void)
{
    bool ready = true;
    bool empty = false;
    bool converted = 42;

    printf("%d %d %d\n", (int)ready, (int)empty, (int)converted);
    return 0;
}

Result

1 0 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