Using define

suggest change

In every version of C, a condition treats the value 0 as false and any other scalar value as true. This applies to if, while, for, do, ?:, !, &&, and ||. The comparison operators themselves produce 0 or 1; they do not accept other integers as their result. If _Bool or the C99 bool names are not available, legacy code sometimes simulates a Boolean type with macros:

#include <stdio.h>

#define bool int
#define true 1
#define false 0

int main(void) {
    bool x = true;  /* Equivalent to int x = 1; */
    bool y = false; /* Equivalent to int y = 0; */
    if (x) /* Functionally equivalent to if (x != 0) or if (x != false) */
    {
        puts("This will print!");
    }
    if (!y) /* Functionally equivalent to if (y == 0) or if (y == false) */
    {
        puts("This will also print!");
    }
}

Don’t introduce this in new code since the definition of these macros might clash with modern uses of <stdbool.h>.

Feedback about page:

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



Table Of Contents