Relational Operators

The relational operators are used to compare two values and tell you whether the comparison being made is true or false. For example, in the second line in the table, we are testing to see whether x is less than or equal to y. If it is true, this expression will return a non-zero value (usually 1). If the condition is false, then a value of zero will be returned. Special attention should be paid to the == (equal to) operator – note that it is not the same as the = (assignment) operator.

Operator Operation Example Result (FALSE=0, TRUE≠0)
< Less than x < y 1 if x less than y, else 0
<= Less than or
equal to
x <= y 1 if x less than or equal to y, else 0
> Greater than x > y 1 if x greater than y, else 0
>= Greater than or
equal to
x >= y 1 if x greater than or equal to y, else 0
== Equal to x == y 1 if x equal to y, else 0
!= Not equal to x != y 1 if x not equal to y, else 0

In conditional expressions, any non-zero value is interpreted as TRUE. A value of 0 is always FALSE.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.