Relational Operators in C

Relational operators in C are used to compare two operands. The result of a relational operation is either true (1) or false (0).

Equal To Operator (==)

Checks whether two operands are equal.

Example: a == b

Not Equal To Operator (!=)

Checks whether two operands are not equal.

Example: a != b

Greater Than Operator (>)

Checks whether the left operand is greater than the right operand.

Example: a > b

Less Than Operator (<)

Checks whether the left operand is less than the right operand.

Example: a < b

Greater Than or Equal To (>=)

Checks whether the left operand is greater than or equal to the right operand.

Example: a >= b

Less Than or Equal To (<=)

Checks whether the left operand is less than or equal to the right operand.

Example: a <= b

Use of Relational Operators

Relational operators are mainly used in decision-making statements such as if, if-else, while, for, and switch conditions.

Common Mistakes

  • Using = instead of == for comparison
  • Comparing floating-point values directly
  • Confusing >= with > and <= with <
  • Assuming relational operators return true or false keywords (they return 1 or 0)