C

1. Relational Operators

These are used to compare two values. The result is always a boolean value (0 or 1).

OperatorDescriptionExample (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!

2. Logical Operators

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.

3. Practical Use Case: Sensor Monitoring

In Embedded Systems, these operators are essential for safety logic. For example:

C
if (temperature > 75 && cooling_fan == OFF) {
    // Turn on the fan to prevent overheating
}
Upcoming Course
Upcoming Course
Learn More
Instructor Tips
Instructor Tips
View Tips
Join Community
Join Community
Join Now