CKTIS / C++
Less-than operator (<)
The < operator tests whether its left operand is less than its right operand. A built-in comparison returns bool and excludes equality. Watch for type conversions, restrictions on pointer comparisons, and the misleading chained expression a < b < c.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
lhs < rhsThe expression lhs < rhs means “lhs is less than rhs”. For numbers, the built-in operator returns bool: true when the relationship holds and false otherwise. Equal values do not satisfy this condition: 7 < 7 produces false.
Arithmetic operands undergo the usual arithmetic conversions before comparison. Mixing signed and unsigned integers can change the interpretation: -1 < 1u produces false because -1 is converted to unsigned int. Do not assume that a mixed-type comparison always matches mathematical comparison.
Relational operators group left to right: a < b < c means (a < b) < c, not a range check. Use (a < b) && (b < c) instead. The example checks strict bounds and prints Boolean values using std::boolalpha.
For pointers to elements of the same array, < compares element order; it does not compare the pointed-to values. Comparing pointers to unrelated objects can yield an unspecified result. For class types, overload resolution can select operator< or a rewritten comparison using operator<=>; the bool result rule applies to the built-in operator.
Examples
#include <iostream>
int main() {
const int value = 7;
const int lower = 3;
const int upper = 10;
static_assert(3 < 7);
static_assert(!(7 < 7));
std::cout << std::boolalpha;
std::cout << (value < upper) << '\n';
std::cout << (value < value) << '\n';
std::cout << ((lower < value) && (value < upper)) << '\n';
}
Result
true false true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.