Relational Operators in C Language

What is the use of Relational operators in Programming Language?

Using relational operators we can compare two variables in the program. The relational operators in C are summarized below, with their meanings.

* Pay particular attention to the equality operator; it consists of two equal  signs, not just one.

This Tutorial introduces a simple version of C’s if control structure that allows a program to make a decision based on the result of some condition.

If the condition is true then the statement in the body of if statement is executed else if the condition is false, the statement is not executed.

Whether the body statement is executed or not, after the if structure completes, execution proceeds with the next statement after the if structure.

Conditions in the if structure is formed with the relational operators which are summarized in the Table

Relational Operators in C

Relational Operator Condition Meaning
!ERROR! unexpected operator ‘=’ a==b a is equal to b
!= a!=b a is not equal to b
< a<b a is less than b
<= a<=b a is less than or equal to b
> a>b x is greater than b
>= a>=b a is greater than or equal to b

Relational operators usually appear in statements which are inquiring about the truth of some particular relationship between variables.

Normally, the relational operators in C are the operators in the expressions that appear between the parentheses.

For example,

(i) if (thisNum < minimumSoFar) minimumSoFar = thisNum
(ii) if (job == Teacher) salary == minimumWage
(iii) if (numberOfLegs != 8 ) thisBug = insect
(iv) if (degreeOfPolynomial < 2) polynomial = linear

Let us see a simple C program containing the If statement (will be introduced in detail in the next unit). It displays the relationship between two numbers read from the keyboard.

It displays the relationship between two numbers read from the keyboard.

Program to find relationship between two numbers

#include <stdio.h>

main ( )


int a, b;

printf ( “Please enter two integers: ”);

scanf (“%d%d”, &amp;amp;a, &amp;amp;b);

if (a <= b)

printf (“ %d <= %d\n”,a,b);


printf (“%d > %d\n”,a,b);


Please enter two integers: 12 17
12 <= 17
We can change the values assigned to a and b and check the result.


Leave a Reply

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

%d bloggers like this: