Early versions of ANSI C lacked a native boolean data type, relying on integer flags (0 for false, non-zero for true). The C99 standard introduced <stdbool.h>, defining type bool alongside true and false.
Boolean Usage in C Code Example
#include <stdio.h>
#include <stdbool.h>
bool is_even(int number) {
return (number % 2 == 0);
}
int main(void) {
bool is_active = true;
bool is_verified = false;
if (is_active && !is_verified) {
printf("Account active but pending verification.\n");
}
printf("Is 42 even? %s\n", is_even(42) ? "true" : "false");
return 0;
}
Comments and corrections