C++ Logical Operators
π C++ Logical Operators
Logical operators ka use conditions ko combine ya negate karne ke liye hota hai.
Ye operators zyada tar if-else, loops, decision making mein use hote hain.
πΉ 1. List of Logical Operators
| Operator | Name | Meaning |
|---|---|---|
&& |
Logical AND | Dono conditions true honi chahiye |
|
||
! |
Logical NOT | Condition ko ulta kar deta hai |
πΉ 2. Logical AND (&&)
β Result true tabhi hoga jab dono conditions true hon.
πΉ 3. Logical OR (||)
β Agar koi ek condition true hai to result true.
πΉ 4. Logical NOT (!)
β true β false
β false β true
πΉ 5. Logical Operators with Comparison
πΉ 6. Using boolalpha (Readable Output)
Output:
πΉ 7. Truth Table
AND (&&)
| A | B | Result |
|---|---|---|
| T | T | T |
| T | F | F |
| F | T | F |
| F | F | F |
OR (||)
| A | B | Result |
|---|---|---|
| T | T | T |
| T | F | T |
| F | T | T |
| F | F | F |
NOT (!)
| A | Result |
|---|---|
| T | F |
| F | T |
β Common Mistakes
β Correct:
π Summary
-
Logical operators conditions combine karte hain
-
&&= AND,||= OR,!= NOT -
Mostly used with comparison operators
