Basic

Switch Case

Goto

Operators

if Statement

Nested if

While Loop

For Loop

Array

Patterns

Excersises


Relational Operators in C Program


A relational operator checks the relationship between two operands. If the relation is true, it returns 1; if the relation is false, it returns value 0.

Operator Description
== Equal to
> Greater than
< Less than
!= Not equal to
>= Greater than or equal to
<= Less than or equal to

Example : pgm.c

#include <stdio.h>
int main()
{
    int a = 3, b = 3, c = 7;

    printf("%d == %d is %d \n", a, b, a == b);
    printf("%d == %d is %d \n", a, c, a == c);
    printf("%d > %d is %d \n", a, b, a > b);
    printf("%d > %d is %d \n", a, c, a > c);
    printf("%d < %d is %d \n", a, b, a < b);
    printf("%d < %d is %d \n", a, c, a < c);
    printf("%d != %d is %d \n", a, b, a != b);
    printf("%d != %d is %d \n", a, c, a != c);
    printf("%d >= %d is %d \n", a, b, a >= b);
    printf("%d >= %d is %d \n", a, c, a >= c);
    printf("%d <= %d is %d \n", a, b, a <= b);
    printf("%d <= %d is %d \n", a, c, a <= c);

    return 0;
}

Output:

3 == 3 is 1
3 == 7 is 0
3 > 3 is 0
3 > 7 is 0
3 < 3 is 0
3 < 7 is 1
3 != 3 is 0
3 != 7 is 1
3 >= 3 is 1
3 >= 7 is 0
3 <= 3 is 1
3 <= 7 is 1