wiki:h-stdbool
Table of Contents
<stdbool.h>
<stdbool.h> provides bool, true, and false (C99) as portable names for the _Bool type. Assigning any non-zero value to bool produces 1, unlike int where 42 stays 42.
In C23, bool became a built-in keyword, but including the header remains portable and harmless.
Example
This example shows that bool truncates non-zero values to 1.
// compile: gcc -std=c99 -o stdboolexample stdboolexample.c // run: ./stdboolexample // description: bool type behavior with various values #include <stdbool.h> #include <stdio.h> int main() { bool a = 42; bool b = -1; bool c = 0; int d = 42; printf("bool(42) = %d\n", a); printf("bool(-1) = %d\n", b); printf("bool(0) = %d\n", c); printf("int(42) = %d\n", d); return 0; }
wiki/h-stdbool.md · Last modified: by 127.0.0.1
