C Programming Relational Operators

Relational operators in c programming; Through this tutorial, you will learn about relational operators in c programming and how to use them in c programs.

Relational Operators In C Programming

A relational operator checks the relationship between two operands. If the relation is true, it returns 1; if the relation is false, it returns value 0.

The below table shows all the Relational Operators in C programming with examples.

OperatorMeaning of OperatorExample
==Equal to7 == 3 is evaluated to 0
>Greater than7 > 3 is evaluated to 1
<Less than7 < 3 is evaluated to 0
!=Not equal to7 != 3 is evaluated to 1
>=Greater than or equal to7 >= 3 is evaluated to 1
<=Less than or equal to7 <= 3 is evaluated to 0

Note that:- Relational operators are used in decision making and loops.

Example 1 – Relational Operators

// Working of relational operators
#include <stdio.h>
int main()
{
    int a = 5, b = 5, c = 10;

    printf("%d == %d is %d \n", a, b, a == b);
    printf("%d == %d is %d \n", a, c, a == c);
    printf("%d > %d is %d \n", a, b, a > b);
    printf("%d > %d is %d \n", a, c, a > c);
    printf("%d < %d is %d \n", a, b, a < b);
    printf("%d < %d is %d \n", a, c, a < c);
    printf("%d != %d is %d \n", a, b, a != b);
    printf("%d != %d is %d \n", a, c, a != c);
    printf("%d >= %d is %d \n", a, b, a >= b);
    printf("%d >= %d is %d \n", a, c, a >= c);
    printf("%d <= %d is %d \n", a, b, a <= b);
    printf("%d <= %d is %d \n", a, c, a <= c);

    return 0;
}

Output

5 == 5 is 1
5 == 10 is 0
5 > 5 is 0
5 > 10 is 0
5 < 5 is 0
5 < 10 is 1
5 != 5 is 0
5 != 10 is 1
5 >= 5 is 1
5 >= 10 is 0
5 <= 5 is 1
5 <= 10 is 1 

Note that:- Relational operators in C are commonly used to check the relationship between the two variables

Example 2 – C Relational Operators with If else Statement

/* C Relational Operators in If Condition */

#include <stdio.h>

void main()
{
  int x = 10;
  int y = 25;

  if (x == y)
   {
     printf(" x is equal to y \n" );
   }

  else
   {
     printf(" x is not equal to y \n" );
   }

}

Output

 x is not equal to y

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *