_Bool C99 Boolean type
_Bool C99 Boolean type
C99's _Bool normalizes scalars to 0 for zero and 1 for nonzero. stdbool.h supplies bool, true, and false; conditions accept any scalar, not only _Bool.
| Category | Type specifiers |
|---|---|
| Kind | Keyword / Statement |
| C standard | C99 |
📝 Syntax
_Bool b = 1; /* Or include <stdbool.h> and use bool b = true; */
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
raw = 1, named = 1, empty = 0
🏷️ Related type specifiers
📚 Related Tutorials
❓ FAQ
QDoes a _Bool variable store 5 after being assigned 5?
ANo. Converting any nonzero scalar to _Bool normalizes it to 1, while zero becomes 0. Reading the object can therefore yield only the Boolean values 0 or 1.
QWhat is the difference between bool and _Bool?
A_Bool is the built-in C99 type keyword. bool is a macro supplied by stdbool.h that expands to _Bool, so declarations using either name have the same type after that header is included.
QWhy are true and false reported as undefined?
AIn C99 and C11, true and false are macros from stdbool.h, not built-in keywords. Add #include <stdbool.h>, or use _Bool directly with 0 and 1.