A structured lesson workspace with readable content, hands-on examples, and a clean path to completion.
C did not have a boolean type for the first 25 years of its existence. C89 had no bool, no true, no false. You used int and the convention that 0 meant false and anything else meant true. C99 introduced _Bool as a keyword. The stdbool.h header added bool, true, and false as macros on top. Understanding this history explains why C code in the wild looks so inconsistent about booleans.
#include <stdio.h>int main(void) {int a = 0;int b = -5;int c = 42;char d = 'A';printf("0 is %s\n", a ? "true" : "false");printf("-5 is %s\n", b ? "true" : "false");printf("42 is %s\n", c ? "true" : "false");printf("'A' (ASCII %d) is %s\n", d, d ? "true" : "false");return 0;}
Zero is false. Everything else is true. Negative numbers are true. The character 'A' is true because its ASCII value is 65. The character '0' is true because its ASCII value is 48, not zero. Only the integer value 0 is false. This is the entire rule.
#include <stdio.h>#include <stdbool.h>int main(void) {bool is_valid = true;bool is_empty = false;_Bool raw = 1;printf("is_valid: %d\n", is_valid);printf("is_empty: %d\n", is_empty);printf("raw: %d\n", raw);printf("sizeof(bool): %zu\n", sizeof(bool));bool from_int = 42;printf("42 as bool: %d\n", from_int);return 0;}
_Bool stores only 0 or 1. Assigning 42 to a _Bool stores 1. It normalizes. sizeof(_Bool) is 1 byte. The stdbool.h header defines bool as _Bool, true as 1, and false as 0. They are macros, not keywords. You can technically #undef them, though you should never do so in sane code.
Codebases written before C99, or targeting compilers without stdbool.h, use int for boolean values. You will see int is_done = 0; and if (!is_done) throughout older C code. This is not wrong. It is the original idiom. When reading legacy code, do not try to modernize every int to bool unless you are already refactoring that file. Match the existing style.
Booleans in C are integers wearing a costume. The stdbool.h header makes the costume more convincing, but underneath, it is all just 0 and nonzero. This matters when you interface with APIs that return int error codes and you are tempted to treat them as booleans. Next module: file I/O, where we finally make programs that persist data beyond a single execution.
Finish the lesson once you have worked through the material. This awards ★ 20 XP.