Wednesday, August 26, 2020

9.1.4 Relational Operators

  • Relational operators are used to compare values of two variables. 
  • As you can use these operators, you can find out if the values of any two variables are equal and if not equal, which variable is the value of which variable and which variable is small? Such operators are used with conditional statements (if, if-else, switch, for, while etc). 
  • These operators are used to check the condition. 
  • When the condition is true, the value becomes true and the value becomes false when the condition is false. 
  • All the relational operators that are being used in C language are given below.

Operators

Description

== (Equal To)

This operator checks whether the values of both variables are equal.

!=(Not Equal To)

This operator checks whether values of both variables are non equal.

< (Lesser Than)

This operator checks whether the left operand is smaller than the value

right operand.

> (Greater Than)

This operator checks whether the left operand is larger than the value

right operand.

<= (Lesser than

equal))

This operator checks whether the left operand is equal to or equal to

the value right operand.

>= (Greater than

equal)

This operator checks whether the left operand is larger than or equal to

the value right operand.



EXAMPLE :-


// Relational operators in C.
#include <stdio.h>
int main()
{
int x = 5, y = 5, z = 15;

printf("%d == %d is : %d \n", x, y, x == y);
printf("%d == %d is : %d \n", x, z, x == z);
printf("%d > %d is :%d \n", x, y, x > y);
printf("%d > %d is : %d \n", x, z, x > z);
printf("%d < %d is : %d \n", x, y, x < y);
printf("%d < %d is : %d \n", x, z, x < z);
printf("%d != %d is : %d \n", x, y, x != y);
printf("%d != %d is : %d \n", x, z, x != z);
printf("%d >= %d is : %d \n", x, y, x >= y);
printf("%d >= %d is : %d \n", x, z, x >= z);
printf("%d <= %d is : %d \n", x, y, x <= y);
printf("%d <= %d is :%d \n", x, z, x <= z);

return 0;
}



OUTPUT


5 == 5 is : 1 5 == 15 is : 0 5 > 5 is :0 5 > 15 is : 0 5 < 5 is : 0 5 < 15 is : 1 5 != 5 is : 0 5 != 15 is : 1 5 >= 5 is : 1 5 >= 15 is : 0 5 <= 5 is : 1 5 <= 15 is :1 

No comments:

Post a Comment

Please do not any spam link in Comment Box