C TutorialLesson 12Free preview
C Booleans
This lesson is part of C · All levels
Summary
Boolean represents a true or false value, and in standard C no built-in bool type is provided. In general, the boolean value is represented by int, where 0 means wrong and a nonzero value means true. Since C99 header stdbool.h is available which provides the bool type with the values true and false to make the code easier to read. This type is very often used with the if, loop, and success status returning functions.
Key points
- In C, 0 is considered false and non-zero numbers are considered true
- The stdbool.h header provides the bool type with the values of true and false (C99)
- Comparisons like a == b yield boolean values of 1 or 0.
- Used for flags and status returning functions such as isSuccess()
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.