Relational Operators
Use relational operators to test equality or inequality of expressions. If an expression evaluates to be true, it returns 1; otherwise it returns 0.
All relational operators associate from left to right.
Relational Operators Overview
Operator | Operation | Precedence |
---|---|---|
== | equal | 9 |
!= | not equal | 9 |
> | greater than | 10 |
< | less than | 10 |
>= | greater than or equal | 10 |
<= | less than or equal | 10 |
Relational Operators in Expressions
Precedence of arithmetic and relational operators is designated in such a way to allow complex expressions without parentheses to have expected meaning:
a + 5 >= c - 1.0 / e /* → (a + 5) >= (c - (1.0 / e)) */
Do not forget that relational operators return either 0 or 1. Consider the following examples:
/* ok: */ 5 > 7 /* returns 0 */ 10 <= 20 /* returns 1 */ /* this can be tricky: */ 8 == 13 > 5 /* returns 0, as: 8 == (13 > 5) → 8 == 1 → 0 */ 14 > 5 < 3 /* returns 1, as: (14 > 5) < 3 → 1 < 3 → 1 */ a < b < 5 /* returns 1, as: (a < b) < 5 → (0 or 1) < 5 → 1*/
Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
What do you think about this topic ? Send us feedback!