Nearby lessons

20 of 72

C - 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 (&& || !)

OperatorMeaningTrue when
&&ANDBoth sides are true
||ORAt least one side is true
!NOTThe 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
Loading editor…
📝 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.

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.