In C, bool stores logical truth values: false is 0 and true is 1. Use these names when a value is intended to act as a condition rather than comparing explicitly with numeric constants. section 3.1 section 5.7.4
Remember these rules:
- A numerical condition is false only when its value is 0; every nonzero value is true. section 3.1
- A bool object has only the values false and true, corresponding to 0 and 1. section 5.7.4
- Do not write values other than 0 or 1 into a bool object or modify its representation bytes directly. section 15.1.6
Use a truth value directly
bool b = ...; if (b) { /* execute when b is true */ } This is clearer than testing ((b != false) == true). Likewise, a numerical variable can be used directly when zero means false and any nonzero value means true. section 3.1
for (size_t i = 0; i < 5; ++i) {
if (i) {
printf("element %zu is %g, \tits square is %g\n",
i,
A[i],
A[i]*A[i]);
}
}
A loop demonstrates a nonzero index used directly as a condition; the body therefore skips the zero index. section 3.1










