Relational Operator in C
0 946
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:
2 != (Not equal to) Checks if the two values are not equal. Type: Binary operator Syntax:
3 > (Greater than) Checks if the left operand exceeds the right operand. Type: Binary operator Syntax:
4< (Less than) Checks if the left operand is beneath the right operand. Type: Binary operator Syntax:
5>= (Greater than or equal to) Checks if the left operand is greater than or equal to the right operand. Type: Binary operator Syntax:
6 <= (Less than or equal to) Checks if the left operand is less than or equal to the right operand. Type: Binary operator Syntax:
1== (Equal to) checks if two values are equal. Type: Binary operator Syntax:
value1 == value2
#include<tdio.h>Output: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; }
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>Output: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; }
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>Output: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; }
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>Output: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; }
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>Output: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; }
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>Output: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; }
a is less than or equal to b
Share:




Comments
Waiting for your comments