411 REFERENCE · Wikibooks
C programming/stdbool.h
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
The header stdbool.h in the C Standard Library for the C programming language contains four macros for a Boolean data type. This header was introduced in C99.
The macros as defined in the ISO C standard are :
bool which expands to _Bool
true which expands to 1
false which expands to 0
__bool_true_false_are_defined which expands to 1
which can be used in an example
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main(void) {
bool keep_going = true; // Could also be `bool keep_going = 1;`
while(keep_going) {
printf("This will run as long as keep_going is true.\n");
keep_going = false; // Could also be `keep_going = 0;`
}
printf("Stopping!\n");
return EXIT_SUCCESS;
}
which will output
This will run as long as keep_going is true.
Stopping!
External links
bd stdbool.h SUS boolean type and values
fr:Stdbool.h
pt:Stdbool.h
ru:Stdbool.h
uk:Stdbool.h
zh:Stdbool.h