Course contentsShow
← C
Lesson 160 of 1,2193. Operators and ExpressionsFree lesson

Greater or equal `>=` and less or equal `<=`

Greater or equal >= and less or equal <=

What you'll learn: How to use the >= and <= operators to check if a value meets or exceeds a specific threshold in C.

The "Inclusive" Boundary

In previous lessons, you learned about "Strict" inequalities like "greater than" (>) and "less than" (<). These are like a "Keep Out" sign: if you are exactly on the line, you don’t count.

Relational operators like >= (Greater than or equal to) and <= (Less than or equal to) are different. They are inclusive. Think of them like a height requirement at an amusement park. If the sign says "You must be 48 inches or taller to ride," a child who is exactly 48 inches is allowed on. They don't have to be 48.1 inches; being "equal to" the limit is good enough.

How they work in C

In C, these operators compare two values and return a result of either 1 (True) or 0 (False).

  • a >= b: Is a larger than b OR exactly the same as b?
  • a <= b: Is a smaller than b OR exactly the same as b?

One important syntax rule: Never put a space between the symbols. C sees >= as a single unit. Writing > = will result in a compiler error. Also, the equals sign always comes second.

Seeing it in Action

Imagine you are writing a program for a thermostat that triggers an alarm if the temperature hits a certain limit.

#include <stdio.h>

int main() {
    int currentTemp = 75;
    int maxLimit = 75;
    int safetyThreshold = 100;

    // Is 75 greater than or equal to 75? Yes!
    int isAtLimit = (currentTemp >= maxLimit); 
    
    // Is 75 less than or equal to 100? Yes!
    int isSafe = (currentTemp <= safetyThreshold);

    printf("At limit: %d\n", isAtLimit); // Outputs 1
    printf("Is safe: %d\n", isSafe);     // Outputs 1

    return 0;
}

In this example, even though currentTemp isn't higher than maxLimit, the >= operator returns true because they are equal. If we had used a simple > operator, the result would have been false.

Why use them?

These operators are the backbone of "range checking." If you are building a game where a player wins if they have 10 or more points, you use score >= 10. If you use score > 10, the player who earns exactly 10 points would be very frustrated to find they haven't won yet!

Key takeaway

Use >= and <= when your boundary line should be included in the "True" result.