Here, in our code we see a new operator i.e. ‘ > ‘ (greater than) in the if statement. We need such operators (like greater than, less than, equal to etc) while making decisions. These operators are called 'relational operators'. These are almost the same relational operators we use in algebra.

Following table summarizes the relational operators.

 

 

Algebraic

In C language

Example

Meaning

Greater than

>

>

x > y

x is greater than y

Equal to

=

==

x == y

X is equal to y

Less than

<

<

x < y

X is less than y

Greater than or equal to

>

>=

x >= y

x is greater than or equal to y

Less than or equal to

<

<=

x <= y

x is less than or equal to y

Not equal to

¹

!=

x != y

x is not equal to y

 

Note that there is no space between ==, >=, <= and !=.

These are considered as single operators.

The operator == (equal to) is different from the operator =. We know that operator = is the assignment operator which is used in assignment statement to assign a value to a variable.

Don't confuse the assignment operator (=) with equal to operator (==). If we write single = in condition of if statement. For example, if we write if ( x = 2 ), the compiler will not give error. This means that it is not a syntax error. The conditional expression in if statement returns a value. In this case, x = 2 will also have some value but it will not in the form of true or false. So it will create a logical error. So be careful while using equal to condition in if statement.

 

 

 

Previous

 

 

TOC

 

 

Next