The C programming language, as of C99, supports Boolean arithmetic with the built-in type _Bool
(see _Bool). When the header <stdbool.h>
is included, the Boolean type is also accessible as bool
.
Standard logical operators &&
, ||
, !
can be used with the Boolean type in any combination.
A program may undefine and perhaps then redefine the macros bool
, true
and false
.
Macros
Macro name | Expands to |
---|---|
bool | _Bool |
true | integer constant 1 |
false | integer constant 0 |
__bool_true_false_are_defined | integer constant 1 |
Example
#include <stdio.h> #include <stdbool.h> int main(void) { bool a=true, b=false; printf("%d\n", a&&b); printf("%d\n", a||b); printf("%d\n", !b); }
Possible output:
0 1 1
See also
C++ documentation for bool |
Please login to continue.