Relational Operator in C
×


Relational Operator in C

26

 Relational operators in C are used to compare two values.

 They return a Boolean value: either true (1) or false (0).

 Relational Operators in C

1==: Equal to

2!=: Not equal to

3>: Greater than

4<: Less than

5>=: Greater than or equal to

6<=: Less than or equal to


1== (Equal to)

checks if two values are equal.

Type: Binary operator

Syntax:

value1 == value2
#include<tdio.h>

int main() {
int a = 5, b = 5;
    
   if (a == b) {
   printf("a is equal to b\n");
   } else {
   printf("a is not equal to b\n");
   }

   return 0;

}

Output:

a is equal to b

2 != (Not equal to)

Checks if the two values are not equal.

Type: Binary operator

Syntax:

value1 != value2
// Program for if two values are not equal
#include<stdio.h> 

int main() {
    int a = 5, b = 10;
    
   if (a != b) {
        printf("a is not equal to b\n");
    } else {
        printf("a is equal to b\n");
    }

    return 0;
}

Output:

a is not equal to b

3 > (Greater than)

Checks if the left operand exceeds the right operand.

Type: Binary operator

Syntax:

value1 > value2
// Program to check if the left operand exceeds the right operand.
#include<stdio.h> 

int main() {
    int a = 10, b = 5;
    
    if (a > b) {
        printf("a is greater than b\n");
    } else {
        printf("a is not greater than b\n");
    }

    return 0;
}

Output:

a is greater than b

4< (Less than)

Checks if the left operand is beneath the right operand.

Type: Binary operator

Syntax:

value1 < value2
// Program to Checks if the left operand is beneath the right operand.
#include<stdio.h> 

int main() {
   int a = 5, b = 10;
    
    if (a < b) {
       printf("a is less than b\n");
    } else {
       printf("a is not less than b\n");
    }

    return 0;
}

Output:

a is less than b

5>= (Greater than or equal to)

Checks if the left operand is greater than or equal to the right operand.

Type: Binary operator

Syntax:

value1 >= value2
 // Program to Checks if the left operand is greater than or equal to the right operand.
#include<stdio.h>
int main() {
    int a = 10, b = 10;
    
    if (a >= b) {
       printf("a is greater than or equal to b\n");
    } else {
        printf("a is less than b\n");
    }

    return 0;
}

Output:

a is greater than or equal to b

6 <= (Less than or equal to)

Checks if the left operand is less than or equal to the right operand.

Type: Binary operator

Syntax:

value1 <= value2
// Program to Checks if the left operand is less than or equal to the right operand
#include<stdio.h> 

int main() {
    int a = 5, b = 10;
   
    if (a <= b) {
        printf("a is less than or equal to b\n");
    } else {
       printf("a is greater than b\n");
    }

    return 0;
}

Output:

a is less than or equal to b


Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments