Relational operators in C are used to compare two values or variables. These operators return a boolean value (1 for true and 0 for false) based on the comparison.

List of Relational Operators

OperatorDescriptionExampleResult
==Equal toa == bTrue if a is equal to b
!=Not equal toa != bTrue if a is not equal to b
>Greater thana > bTrue if a is greater than b
<Less thana < bTrue if a is less than b
>=Greater than or equal toa >= bTrue if a is greater than or equal to b
<=Less than or equal toa <= bTrue if a is less than or equal to b

Example Usage:

#include <stdio.h>

int main() {

    int a = 10;

    int b = 20;

    printf(“a == b: %d\n”, a == b);  // False, outputs 0

    printf(“a != b: %d\n”, a != b);  // True, outputs 1

    printf(“a > b: %d\n”, a > b);    // False, outputs 0

    printf(“a < b: %d\n”, a < b);    // True, outputs 1

    printf(“a >= b: %d\n”, a >= b);  // False, outputs 0

    printf(“a <= b: %d\n”, a <= b);  // True, outputs 1

    return 0;

}

Output:

a == b: 0

a != b: 1

a > b: 0

a < b: 1

a >= b: 0

a <= b: 1

Relational operators are critical for decision-making in conditional statements such as if, while, and for loops in C programming

error: Content is protected !!
Open chat
1
Hi,how Can We Help You ?