_Bool

From cppreference.com
< c‎ | language

Implements a Boolean type.

Contents

[edit] Syntax

_Bool

[edit] Explanation

An object declared as type _Bool is large enough to store the values 0 and 1.

When any scalar value is converted to _Bool, the result is 0 if the value compares equal to 0; otherwise, the result is 1.

[edit] Keywords

_Bool

[edit] Example

#include <stdio.h>
 
int main(void)
{
    printf("sizeof(_Bool) = %zu\n", sizeof(_Bool));
 
    _Bool b;
    b = 2;
    printf("b  = %d\n", b);    // 2 or 1?
    printf("!b = %d\n", !b);   // 0
 
    b = 0;
    printf("!b = %d\n", !b);   // 1
 
    if (b) printf("true\n");   // false
    else   printf("false\n");
 
    return 0;
}

Possible output:

sizeof(_Bool) = 1
b  = 1
!b = 0
!b = 1
false