In C, a comparison operator compares values and produces a Boolean result: false is represented by 0, and true by 1. The operators are ==, !=, <, >, <=, and >=. section 4.3 section 4.3.1
The comparison operators divide into these practical forms:
- == tests equality, while != tests inequality. section 4.3.1
- < and > perform strict less-than and greater-than comparisons. section 4.3.1
- <= tests less than or equal, while >= tests greater than or equal. section 4.3.1
- Comparison results can participate in arithmetic, control statements, and array indexing because they are 0 or 1. section 4.3.1
TAKEAWAY: Comparison operators return false or true, which are simply the values 0 and 1. This makes a comparison an expression that can be stored, counted, or used to select an array element. section 4.3.1 section 4.6
Counting comparison results
size_t c = (a < b) + (a == b) + (a > b); size_t d = (a <= b) + (a >= b) - 1; Each comparison contributes 0 or 1. Consequently, c is always 1, while d is 1 when a and b are equal and 0 otherwise. section 4.3.1
size_t c = (a < b) + (a == b) + (a > b);
size_t d = (a <= b) + (a >= b) - 1;
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":3},{\"line\":0,\"ch\":9}],[{\"line\":1,\"ch\":3},{\"line\":1,\"ch\":9}],[{\"line\":0,\"ch\":3},{\"line\":0,\"ch\":9}],[{\"line\":1,\"ch\":3},{\"line\":1,\"ch\":9}]]"}
!@%STYLE%@!
Inspect the compact expressions that combine comparison results arithmetically. section 4.3.1







