Modern C (C11/C17/C23)

bool, true and false as keywords (C23)

/ bool /

C did not always have a real boolean type; for a long time programmers used int with the convention that 0 meant false and anything else true. C99 added a built-in boolean type spelled _Bool, with the friendlier names bool, true, and false provided as macros if you included <stdbool.h>. C23 finishes the cleanup: bool, true, and false become proper KEYWORDS of the language, available with no header at all.

Under the hood, the boolean type holds only the values 0 and 1: assigning any nonzero value to a bool stores 1, and assigning 0 stores 0 — so bool b = 5; leaves b holding 1, not 5. In C23 true and false are constants of type bool equal to 1 and 0, and the keyword bool is the type itself (the underscore-prefixed _Bool name still exists as the underlying spelling for compatibility, but you no longer need <stdbool.h> to write bool). This brings C closer to C++ and removes a small but persistent piece of boilerplate.

It matters for clarity: a function returning bool documents 'yes or no' far better than one returning int, and the type's 0/1 normalization avoids surprises in comparisons. The caveat worth stating: bool is still an arithmetic type that participates in integer promotions, and it is distinct from a single bit of storage — sizeof(bool) is at least 1 byte. Also, code that previously included <stdbool.h> still compiles fine in C23; the header simply became unnecessary.

// C23: no #include needed bool ready = true; bool b = 5; // b holds 1, not 5 (any nonzero -> 1) if (ready && !b) { /* ... */ } // sizeof(bool) is at least 1 byte, not 1 bit

In C23 bool/true/false are keywords; assigning a nonzero value normalizes to 1, and a bool still occupies at least one byte.

bool stores only 0 or 1 (any nonzero assignment becomes 1) yet still takes at least a byte and promotes to int in arithmetic; old code that included <stdbool.h> keeps working in C23.

Also called
native bool_Bool keyword cleanup原生布林型別