liveBook · Manning

Boolean

As explained in Modern C

bool is the C standard boolean type whose values represent false or true.

A Boolean value represents a condition as false or true. In C, bool comes from stdbool.h; its values are false and true, corresponding technically to 0 and 1. section 3.1 section 5.7.4

Use a Boolean directly

Given bool b = ...;, write if (b) { ... } rather than if ((b != false) == true) { ... }. A condition should use an existing truth value directly. section 3.1

Keep these rules in view:

  • Treat 0 as logical false and every nonzero numerical value as logical true. section 3.1
  • Use bool when assignment should reduce a stored value to false or true; Boolean assignment follows a special rule rather than ordinary modulus behavior. section 5.7.4
  • Do not compare a truth value to 0, false, or true; use the value itself as the condition. section 3.1
   bool b = ...;
   ...
   if (b) {
     ...
   }


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":2,\"ch\":3},{\"line\":2,\"ch\":5}]]"}
!@%STYLE%@!

Inspect the compact form of a Boolean condition and compare it with the redundant form. section 3.1

How Modern C covers it

How deep it goes
Defines truth rules, header names, representations, and assignment behavior without developing deeper implementation details.
Examples
Uses if (i), equality comparisons, and bool b conditions to contrast direct truth testing with redundant comparisons.
What it assumes
Assumes basic C conditions and expressions while teaching numerical truth rules and Boolean naming explicitly.
What you can do after
Apply Boolean values through stdbool.h and write clearer conditions without redundant truth comparisons.
How it connects
Connects Boolean values with conditional execution, scalar types, equality operators, and assignment.

Also explained in

Compare how 11 books explain boolean →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.