Relational Operators in C

Relational Operator in C

The main use of this operator comparison two expression. The output of relational expression is either true(1) or false(0).

So what are operator that use for relational expression, (<,<=,>,>=,==,!=). These operator is called as a relational operator.

For example: checking if one operand is equal to the other operand or not, an operand is greater than the other operand or not etc.

relational operator

Implementation of Relational operator

We know that Relational operator have six operator So, we can use this  operator in the below program. Firstly we are use greater than the value of operator if the value is greater than print the greatest value.second we are greater than or equal to value if the value is greater than or equal to the value than print the value.third is the value is smaller then we can use the smallest value of two number and print the smallest value.fourth is we are greater than or equal to value if the value is greater than or equal to the value than print the value. fifth is  if the two value is same or equal then print the equal to value.six is not equal to the value then print the value it is not equal of two number.

Relational Operators in C

Code for Relational Operator

Run
#include <stdio.h>
int main() 
{
    int x = 10, y = 15;
    printf ("x = %d\n", x);
    printf ("y = %d\n\n", y);
      // Is x is greater than y?
    printf ("x > y : %d\n", x > y);
    // Is x is greater than or equal to y?
    printf ("x >= y : %d\n", x >= y);
    // Is x is smaller than y?
    printf ("x < y : %d\n", x < y);
    // Is x is smaller than or equal to y?
    printf ("x <= y : %d\n", x <= y);
    // Is x is equal to y?
    printf ("x == y : %d\n", x == y);
    // Is x is not equal to y?
    printf ("x != y : %d\n", x != y);
    // Signal to operating system everything works fine
    return 0;
}

Output

x = 10
y = 15

x > y : 0
x >= y : 0
x < y : 1
x <= y : 1
x == y : 0
x != y : 1 

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription