skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
h-stdbool
This page is read only. You can view the source, but not change it.
# <stdbool.h> **[<stdbool.h>](https://en.cppreference.com/w/c/header/stdbool)** 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. ```c // 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; } ``` ## Common types and macros - `bool`: boolean type (holds 0 or 1) - `true`: macro for 1 - `false`: macro for 0
Page Tools
Show pagesource
Backlinks
Back to top