Relational operators or comparison operators compare two operands which are on the left and right side of the operator. The result of such a comparison operation will be either TRUE or FALSE. Relational operators available in C are :
Operator | Meaning |
---|---|
== | Equal To - Left side and right side operands are same |
!= | NOT Equal To - Left side and right side operands are different |
> | Greater Than - Left side operand is greater than right side |
< | Less Than - Left side operand is less than right side |
>= | Greater Than or Equal To - Left side operand is greater than or equal to right side |
<= | Less Than or Equal To - Left side operand is less than or equal to right side |
Relational operators are generally used with conditional statements in C such as if, while, for.
Consider three variable a, b and c as below
a = 10; b = 15; c = 10;
The table below shows some expressions using above variables and the results.
Expression | Meaning | Result |
---|---|---|
(a = c) | a Equals c | TRUE |
(a < b) | a Less Than b | TRUE |
(b >= c) | b Greater Than or Equal To c | TRUE |
(a != c) | a Not Equal To c | FALSE |
(a > b) | a Greater Than b | FALSE |
(b <= c) | b Less Than or Equal To c | FALSE |
Nothing yet..be the first to share wisdom.