Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Comparisons are fundamental to conditional branching. C++ includes traditional boolean comparison operators and introduced the revolutionary Three-Way Comparison Operator <=> (the "Spaceship Operator") in C++20.
All standard relational operators yield a boolean value (true or false):
== : Equal to!= : Not equal to< : Less than<= : Less than or equal to> : Greater than>= : Greater than or equal to<=>)Prior to C++20, if you authored a custom struct or class, you had to manually implement six separate comparison operators (==, !=, <, <=, >, >=). With C++20's Three-Way Comparison (<=>), a single operator provides complete ordering:
<=>:std::strong_ordering: Values that are substitutable (e.g. integers: if a == b, f(a) == f(b)).std::partial_ordering: Values with non-comparable states (e.g. floating-point NaN).Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Arithmetic, Assignment, and Compound Operators | Logical Operators and Short-Circuiting |
Test your understanding of this lesson with 1 questions. Each question has one correct answer.