Nearby lessons
30 of 124C - Logical Operators
Logical Operators is one of the foundational topics in C programming. This lesson explains Logical Operators (&& || !) and Program: AND, OR and NOT with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid.
Logical Operators (&& || !)
| Operator | Meaning | True when |
|---|---|---|
| && | AND | Both sides are true |
| || | OR | At least one side is true |
| ! | NOT | The condition is false |
Trainer's Note: Memory trick: `&&` is strict — BOTH must say yes. `||` is relaxed — ONE yes is enough. `!` is the liar — it flips the answer. Practise: ! on a true condition gives false (0).
Program: AND, OR and NOT
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.