C – Relational Operators

C – Relational Operators 2017-08-05T17:44:04+00:00

Relational Operators :

Relational operators are used to compare, logical, arithmetic and character expression. Each of these six relational operators takes two operands. Each of these operators compares their left side with their right side. The whole expression involving the relation operator then evaluate to an integer. It evaluates to 0 if the condition is false and 1 if it is true.

Operator Meaning
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
== Equal to
!= Not equal to


The concept of comparison certainly implies different meanings depending on the data type of the variables compared. Operators presented in this table are suitable for comparing numeric values ​​or ordinal (individual characters or enumerated values), but not to compare strings or lists of any kind. String comparison requires the use of features designed specifically for this purpose, like strcmp() . See here a description of the string comparison functions offered by C. Note also that these functions do not properly handle diacritics, it will be necessary to use other methods to compare strings correctly in languages ​​that contain them.

Suppose that a and b are integer variables whose values are 100 and 4, respectively. Several arithmetic expressions involving these variables are shown below, together with their resulting values.

Expression Interpretation Value
a<b False 0
a>b True 1
a<=b False 0
a>=b True 1
a==b False 0
a!=b True

Prev Next