C Booleans
1. What is a Boolean?
-
A Boolean represents truth values:
-
True → 1
-
False → 0
-
-
Used in conditional statements, loops, and logical operations.
Note: C does not have a built-in
booltype in older versions (C89/C90).
In modern C (C99 and later), you can use_Boolorstdbool.hfor boolean variables.
2. Boolean Using _Bool
-
_Boolis a built-in type in C99. -
Values: 0 (false) or 1 (true)
Output:
3. Boolean Using stdbool.h
-
Modern C allows
booltype withtrueandfalsekeywords.
Output:
%dprints1for true and0for false.
4. Boolean in Conditional Statements
Output:
5. Boolean in Expressions
-
Logical operators return 0 or 1 → Boolean result:
Output:
6. Key Points
-
Boolean represents true (1) or false (0).
-
Use
_Bool(C99) orstdbool.hfor modern C programs. -
Boolean values are commonly used in if statements, loops, and logical operations.
-
Logical operators like
&&,||, and!produce Boolean results.
