Logical Operators

Last Updated: Jan 2026


Logical operators are used to combine or invert conditions — they return true or false depending on logic results.


🗂 List of Logical Operators

OperatorNameDescriptionExampleResult
&&AND

Returns true if all conditions are true

(5 > 2) && (10 > 5)true
||OR

Returns true if any one condition is true

(3 > 5) || (10 > 7)true
!NOTReverses the result (true → false, false → true)!(5 > 2)false

✏ Mini Example

int a = 10;
int b = 5;
int c = 7;

printf("%d\n", (a > b) && (a > c)); // true  (both true)
printf("%d\n", (a > b) || (a < c)); // true  (one is true)
printf("%d\n", !(a > b)); // false (reverse)

💡 Quick Practice

  1. Check if both conditions x > 5 and y < 10 are true.
  2. Print "Welcome" if userName exists, using &&.
  3. Use || to set a default name when user input is empty.
  4. Exercises Set

Liked This Tutorial

Scan QR Code To Leave A Review Or

Click Here To Leave A Review
Scan QR