Showing posts with label Examples of Relational Operator. Show all posts
Showing posts with label Examples of Relational Operator. Show all posts

Sunday, January 31, 2016

Relational operator

Relational operators are binary operators(operates on two operands) and are used to relate or compare two operands. There are four relational operators in C (i.e <, <=, >, >=). If the relationship between the operands is correct, it will return 1 and returns 0 otherwise.
Apart from four relational operators, C has two equality operator (== and !=) as well for comparing operands. Now let's take a look at different relational and equality operators and how they operate on the operands.
OperatorNameDescriptionExample
<'Less than' operatorChecks if the first operand is less than second operand and returns 1 if it's true, else returns 010 < 5 returns 0 and5 < 10 returns 1
<='Less than or equals to' operatorChecks if the first operand is less than or equals to second operand and returns 1 if it's true, else returns 010 <= 10 returns 1 and 10 <= 5 returns 0
>'Greater than' operatorChecks if the first operand is greater than second operand and returns 1 if it's true, else returns 010 > 5 returns 1 and5 > 10 returns 0
>='Greater than or equals to' operatorChecks if the first operand is greater than or equals to second operand and returns 1 if it's true, else returns 010 >= 10 returns 1 and 5 >= 10 returns 0
==Equality operatorChecks if the two operands are equal are returns 1 if it's true, else returns 010 == 10 returns 1 and 10 == 1 returns 0
!=Non-equality operatorChecks if the two operands are equal are returns 1 if they are not equal, else returns 010 != 10 returns 0 and 10 != 1 returns 1