---
title: 3.9 Comparison Operators
description: Comparison operators are relational operators used to compare the relative values of two operands. They determine whether one operand is greater than, less than, greater than or equal to, or less than or equal to another operand. The result of…
url: "https://edcret.in/docs/cpp-programming/operators-cplusplus/3-9-comparison-operators/"
updated: "2026-07-28"
category: C++ Programming / Operators
---

# 3.9 Comparison Operators

Comparison operators are relational operators used to compare the relative values of two operands. They determine whether one operand is greater than, less than, greater than or equal to, or less than or equal to another operand. The result of each comparison is a Boolean value.

Comparison operators are commonly used in conditional statements, loops, and decision-making expressions.

## Source Code

```
#include <iostream>

int main()
{
    int num1 = 25;
    int num2 = 30;

    std::cout << "num1 < num2  : " << (num1 < num2) << '\n';
    std::cout << "num1 > num2  : " << (num1 > num2) << '\n';
    std::cout << "num1 <= num2 : " << (num1 <= num2) << '\n';
    std::cout << "num1 >= num2 : " << (num1 >= num2) << '\n';

    return 0;
}
```

## Output

```
num1 < num2  : 1
num1 > num2  : 0
num1 <= num2 : 1
num1 >= num2 : 0
```

## Explanation

- The less-than operator (`<`) returns `true` if the left operand is smaller than the right operand.
- The greater-than operator (`>`) returns `true` if the left operand is greater than the right operand.
- The less-than-or-equal-to operator (`<=`) returns `true` if the left operand is less than or equal to the right operand.
- The greater-than-or-equal-to operator (`>=`) returns `true` if the left operand is greater than or equal to the right operand.
- All comparison operators produce a result of type `bool`.
- By default, `std::cout` displays Boolean values as `1` for `true` and `0` for `false`.
- Comparison operators evaluate expressions without modifying either operand.
- `return 0;` terminates the program successfully.
