Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

bool — Boolean type

In C23, bool is the Boolean type keyword; _Bool denotes the same type. The <stdbool.h> header is unnecessary.

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

Syntax

bool flag = true;
_Bool other = false;

bool stores false and true, corresponding to 0 and 1. In C23, _Bool is an alternative spelling of the same keyword, not a separate type.

Conversion to bool maps arithmetic zero, a null pointer, and a value of type nullptr_t to false; other scalar values become true. Thus -7 becomes true, not -7.

In C23, bool, true, and false need no <stdbool.h>. The example explicitly converts values to int before printing with %d.

Examples

#include <stdio.h>

int main(void)
{
    bool enabled = true;
    _Bool empty = 0;
    bool converted = -7;

    printf("%d %d %d\n", (int)enabled, (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