RELATIONAL
OPERATORS
Relational operators in C are used to compare the
relationship between two operands. They evaluate the conditions and return a
Boolean result, which is either true or false. Relational operators are
commonly used in conditional statements and loops to make decisions based on
comparisons. Here are the relational operators in C:
1. Equal to (==): Checks if two operands are equal.
Example:
int a = 5;
int b = 7;
if (a == b)
{ // This condition
is false, so the code inside the if block will not execute. }
2. Not equal to (!=): Checks if two operands are not equal.
Example:
int a = 5;
int b = 7;
if (a != b)
{ // This condition
is true, so the code inside the if block will execute.}
3. Greater than (>): Checks if the first operand is
greater than the second.
Example:
int a = 5;
int b = 7;
if (a > b)
{ // This condition
is false, so the code inside the if block will not execute }
4. Less than (<): Checks if the first operand is less
than the second.
Example:
int a = 5;
int b = 7;
if (a < b)
{ // This condition
is true, so the code inside the if block will execute.}
5. Greater than or equal to (>=): Checks if the first
operand is greater than or equal to the second.
Example:
int a = 5;
int b = 7;
if (a >= b) { // This condition is false, so the code
inside the if block will not execute. }
6. Less than or equal to (<=): Checks if the first
operand is less than or equal to the second.
Example:
int a = 5;
int b = 7;
if (a <= b)
{ // This condition is true, so the code inside the if block
will execute.}
Relational operators return a value of 1 (true) if the
condition is satisfied, and a value of 0 (false) otherwise. These operators can
be used with variables, constants, or expressions to compare values and make
logical decisions in your C programs.