These are used to compare two values. The result is always a boolean value (0 or 1).
| Operator | Description | Example (a=10,b=20) | Result |
| == | Equal to | $a == b$ | 0 (False) |
| != | Not equal to | $a != b$ | 1 (True) |
| > | Greater than | $a > b$ | 0 (False) |
| < | Less than | $a < b$ | 1 (True) |
| >= | Greater than or equal to | $a >= 10$ | 1 (True) |
| <= | Less than or equal to | $b <= 15$ | 0 (False) |
Common Mistake: Don't confuse == (comparison) with = (assignment). Using = in an if statement is a classic bug that assigns a value instead of checking it!
Logical operators allow you to combine multiple relational expressions together.
&& (Logical AND): Returns True only if both conditions are true.
Example: (5 > 3 && 10 < 20) is True.
|| (Logical OR): Returns True if at least one condition is true.
Example: (5 > 3 || 10 > 20) is True.
! (Logical NOT): Reverses the state of a condition (True becomes False and vice versa).
Example: !(5 > 3) is False.
In Embedded Systems, these operators are essential for safety logic. For example:
if (temperature > 75 && cooling_fan == OFF) { // Turn on the fan to prevent overheating }
Copyright ©2025. All Rights Reserved Emblab THE RAVE INNOVATION