Relational operators

Relational operators

In C programming language, relational operators are used to compare two or more variable values ​​or expressions declared in the program. Based on the comparison result of the relation operator, the output either returns true (1) value or displays false (0) output value.

Relational operators

So let’s now know about the relational operators in C language.

Equals (==) Relational Operator.

Equals relation operator checks two different program variable values ​​in C language program whether the two variable values ​​are equal to the values ​​of equal operator operands or not.

Example of the relation equals (==) operator.

int p = 5, q = 5;

if (p == q)

{

// given equal condition is true

}

Not equal (!=) relational operator.

It checks in the current C program whether the two operand values ​​are not equal in the given program variable condition.

Not equal (!=) relational operator example.

int p = 3, q ​​= 6;

if (p != q)

{

// the given not equal condition is true

}

Greater Than (>) Relational Operator.

Greater Than relation operator checks the value of two different variables declared in the current C program whether the left operand value is greater than the right operand variable value or not.

Greater Than (>) relational Operator Example.

int p = 7, q = 6;

if (p > q)

{

// the given condition is true

}

Less Than (<) Relational Operator.

Less Than relational operator checks whether the left operand declare variable value is less than the right operand variable value in the given C program.

Less Than (<) Relational Operator.

int p = 3, q ​​= 5;

if (p < q)

{

// the given condition is true

}

Greater than or equal to (>=) relational operator.

Greater than and equal to relational operator checks whether the left operand declare variable value is greater than or equal to the right operand value in the current C program.

Greater than or equal to (>=) relational operator example.

int p = 1, q = 1;

if (p >= q)

{

// the given condition is true

}

Less Than or Equal To (<=) relational operator.

Less than and equal relational operator in C program checks whether the value of left operand declared program variable value in the current program is less than or equal to the value of right operand.

Less than or equal to (<=) relational operator example.

int p = 1, q = 2;

if (p <= q)

{

// the given condition is true

}

Use of Relational Operators.

Relational operators in C programming language are often used in programming loops or conditional statements like if, while, and for loops. Sometimes we use relational operators to check the relationship between any two conditions.

The result of any relational operation operand used in C program is displayed in the output as either true (1) or false (0).

Most relational operators are used to test numeric programming value types as well as character programming values.