Using the Intrinsic built-in Type Bool

suggest change

Added in the C standard version C99, _Bool is also a native C data type. It is capable of holding the values 0 (for false) and 1 (for true).

#include <stdio.h>

int main(void) {
    _Bool x = 1; 
    _Bool y = 0;
    if(x) /* Equivalent to if (x == 1) */
        puts("This will print!");
    if (!y) /* Equivalent to if (y == 0) */
        puts("This will also print!");

_Bool is an integer type but has special rules for conversions from other types. The result is analogous to the usage of other types in if expressions. In the following

_Bool z = X;

To use nicer spellings bool, false and true you need to use <stdbool.h>.

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents