A comparison operator evaluates a relational condition between two operands and produces a Boolean result. C provides ==, !=, <, >, <=, and >=; the last two include equality. section 4.0 section 4.4.1
Use comparisons as values as well as conditions:
- Comparison operators return false or true, represented numerically as 0 and 1. section 4.4.1
- Use them directly in control statements such as if conditions. section 4.4.1 section 3.1
- Use their results in arithmetic or array indexing when a numeric truth value is useful. section 4.4.1
- Use not_eq as an alternative spelling for != only with <iso646.h>; the feature is rarely used. section 4.4.1
Combining 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, so these expressions encode relationships between a and b numerically. section 4.4.1
size_t c = (a < b) + (a == b) + (a > b); size_t d = (a <= b) + (a >= b) - 1;
Inspect a compact listing that combines strict and inclusive comparisons as arithmetic values. section 4.4.1







