DEV Community

Discussion on: Boolean in C

Collapse
 
pgradot profile image
Pierre Gradot

Oh come on... C has a (very basic) bool type since C99:

#include <stdbool.h>
#include <stdio.h>

int main(void) {
    bool a = true;
    bool b = false;

    if (a && !b) puts("hello, bool in C99");    
}
Enter fullscreen mode Exit fullscreen mode

; )

Collapse
 
clavinjune profile image
Clavin June

hmm interesting, should've checked the content of stdbool

Collapse
 
pauljlucas profile image
Paul J. Lucas

No, the actual Boolean type in C is spelled _Bool. You can use that without including any header. stdbool.h simply defines the macros:

#define bool _Bool
#define false 0
#define true 1
Enter fullscreen mode Exit fullscreen mode

as a convenience.