Nearby lessons
29 of 124C - Relational Operators
Relational Operators is one of the foundational topics in C programming. This lesson explains Relational (Comparison) Operators (== != < > <= >=) and Program: all six relational operators with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
Relational (Comparison) Operators (== != < > <= >=)
These compare two values and give either true (1) or false (0). C has no boolean word for beginners — it uses 1 for true and 0 for false.
| Operator | Meaning | Example |
|---|---|---|
| == | Equal to | a == b |
| != | Not equal to | a != b |
| < | Less than | a < b |
| > | Greater than | a > b |
| <= | Less than or equal to | a <= b |
| >= | Greater than or equal to | a >= b |
In simple words: a comparison always answers one question — true or false. In C, true is printed as 1 and false as 0. No other answer is possible.
Program: all six relational operators
Example02
📝 Key Takeaways
- Operators: arithmetic (+ - * / %), relational (== != < > <= >=), logical (&& || !), assignment (= += -= *= /= %=), ++ --, ternary ?:.
- Each operator family has its own complete program — copy and run one at a time.
- Integer division drops decimals: 5/2 = 2; use 5.0/2 for 2.5.
- % gives the remainder and works only on integers.
- a++ uses then increases; ++a increases then uses.
- Ternary: condition ? value1 : value2.
- Use brackets to control the order of evaluation.
🧠 Test Your Knowledge
1 QuestionsProgress: 0 / 1