C Booleans

Booleans (True / False) – Complete Guide
Unlike many modern languages, C does not have a built-in boolean type (in old C).
Instead, C represents true and false using integers.
Boolean Concept in C
In C:
0 →
falseAny non-zero value →
true
Using Integers as Booleans (Traditional C)
- This is how booleans were handled before C99
Boolean Type Using <stdbool.h> (Recommended)
From C99 standard, C provides a proper boolean type.
Include Header
Boolean Keywords
| Keyword | Meaning |
|---|---|
bool | Boolean type |
true | 1 |
false | 0 |
Example Using bool
- Cleaner
- More readable
- Interview-friendly
Boolean-with Conditions
- Very common in real programs
Boolean-with Logical Operators
Boolean with Comparison Operators
- All comparisons return boolean values
Boolean-in Loops
Used in:
Menu loops
Game loops
Embedded systems
Printing Boolean Values
C does not print true / false automatically.
Custom Print
Boolean vs Integer
- Valid
- Value becomes
1(true)
Common Mistakes
- Forgetting
#include <stdbool.h> Expectingprintf("%b", b)(not supported)- Confusing
=and== Assuming only1is true
Any non-zero value is true
Interview Questions (Very Important)
Does C support boolean data type?
Difference between
intandbool?What values represent true and false in C?
What header file defines
bool?Output of
if(5)?
Real-Life Use Cases
Login status
Validation flags
Feature enable/disable
Loop control
Error handling
Summary
- C uses 0 and non-zero for false/true
<stdbool.h>providesbool,true,falseBooleans improve code readability- Essential for conditions, loops & interviews
