Advertisement

Relational Operators

C Language Operators 📅 May 2026 ⏱ 1 min read 🆓 Free

Relational (Comparison) Operators in C

Relational operators compare two values and return 1 (true) or 0 (false). They are used in if statements and loops to make decisions.

OperatorMeaningExampleResult
==Equal to5 == 51 (true)
!=Not equal to5 != 31 (true)
>Greater than10 > 71 (true)
<Less than3 < 81 (true)
>=Greater than or equal5 >= 51 (true)
<=Less than or equal3 <= 20 (false)
c
#include <stdio.h>

int main() {
    int a = 10, b = 20, c = 10;
    
    printf("a=%d, b=%d, c=%d\n\n", a, b, c);
    
    printf("a == b  : %d\n", a == b);  // 0 (false)
    printf("a == c  : %d\n", a == c);  // 1 (true)
    printf("a != b  : %d\n", a != b);  // 1 (true)
    printf("a >  b  : %d\n", a >  b);  // 0 (false)
    printf("a <  b  : %d\n", a <  b);  // 1 (true)
    printf("a >= c  : %d\n", a >= c);  // 1 (true, equal)
    printf("b <= a  : %d\n", b <= a);  // 0 (false)
    
    // Practical use
    int marks = 75;
    if (marks >= 40)
        printf("\nResult: PASS\n");
    else
        printf("\nResult: FAIL\n");
    
    return 0;
}
▶ Output
a=10, b=20, c=10

a == b  : 0
a == c  : 1
a != b  : 1
a >  b  : 0
a <  b  : 1
a >= c  : 1
b <= a  : 0

Result: PASS
⚠ Warning: Do NOT confuse == (comparison) with = (assignment)! Writing if (x = 5) instead of if (x == 5) is a classic bug — it assigns 5 to x and always evaluates to true!
Advertisement
← Back to C Language Index