CKTIS / C++
Greater-than operator (>)
The > operator tests whether the left operand is greater than the right. A built-in comparison returns bool; equal values produce false. Learn about numeric conversions, chained-comparison pitfalls, and the distinction between built-in and overloaded comparisons.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
left > rightThe expression left > right means a strict “greater than” comparison. For a built-in numeric comparison, the result has type bool: true when the left value is greater, and false otherwise, including equality. In contrast, >= means “greater than or equal to”.
Numbers undergo the usual arithmetic conversions before comparison. Mixing signed and unsigned types can change the expected result: -1 > 1u produces true because -1 is converted to unsigned int. Prefer operands with compatible types and choose conversions deliberately.
Do not write mathematical chains: a > b > c is interpreted as (a > b) > c. To test both relationships, use a > b && b > c. For pointers, ordering is specified in cases such as elements of the same array; do not assume a portable ordering of unrelated objects.
For class types, overload resolution can select operator> or a comparison rewritten from operator<=>. The built-in operator's rules, including its bool result type, do not describe every overload. The supplied source is an evolving draft, not a frozen C++23 text; the example targets compilation with -std=c++23.
Examples
#include <iostream>
int main() {
constexpr int score = 12;
constexpr int limit = 10;
static_assert(score > limit);
static_assert(!(limit > limit));
std::cout << std::boolalpha;
std::cout << (score > limit) << '\n';
std::cout << (limit > limit) << '\n';
}
Result
true false
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.