๐ Kahani Ke Shuruaat – Ek Andhera IF Statement...
Ek raat Guddu coding karat rahaa. Suddenly unka saamne ek aisan line aail:
result = (condition) ? expression1 : expression2;
Guddu soch me pad gaya... "Ee ka bhootni ke code baa? IF-ELSE ke shortcut? Aur ee ‘?’ aur ‘:’ ka chakkar baa?"
"Choose quickly... warna code deadlock me phans jaayi!"
☠️ Ternary Operator – Ek Line Me Faisla, Zindagi Ya Maut!
๐ Syntax:
condition ? true_value : false_value;
Ee ek shortcut IF-ELSE baa. Jaise:
int age = 18; string result = (age >= 18) ? "Adult" : "Kid";
Agar condition true ba, to "Adult" assign ho jaayi, warna "Kid".
๐ง♂️ Example – Jab Dracula Entry Maare Coding Class Me
int bloodUnits = 2; string status = (bloodUnits >= 3) ? "Dracula Full Power" : "Dracula Weak"; cout << status;
Dracula ke power tabhi active hoyi jab bloodUnits ≥ 3, nahi to wo kamjor ho jaayi – aur bhatakti ruh ban jaayi! ๐จ
๐ชฆ Nested Ternary – Jab ek galti se dusra bhoot active ho jaayi!
int fearLevel = 7;
string reaction = (fearLevel > 8) ? "Run Away!" :
(fearLevel > 5) ? "Shiver & Stay" :
"Face the Ghost";
cout << reaction;
Jab bhoot samne ho, aur tum confuse ho jaawe ki bhaagi ke na ladhi – tab ee nested ternary kaam aave!
๐ฑ Common Mistake – Jab Bracket Na Lagawa, aur Bhoot Logic Pakad Le!
int x = 5, y = 10; int result = x < y ? x++ : y++; cout << result;
Looks simple? But agar bracket na lagawa, to priority ke bhoot chha jaayi.
Correct way:
int result = (x < y) ? (x++) : (y++);
๐ฏ️ Comparison with IF-ELSE – Jab candle ke roshni me faisla lena pare
// IF-ELSE version
if(age >= 18)
result = "Adult";
else
result = "Kid";
// Ternary version
result = (age >= 18) ? "Adult" : "Kid";
“Same logic... lekin Ternary horror movie ke climax jaisan – ekdum short aur deadly!”
๐ Real-Life Haunted Joke
Sweety: "Guddu, hum 2 second me faisla chahta!"
Guddu (with ternary):"Sweety mood == kharab ? chocolate : ignore;"
Sweety: "Kaa?! Ignore? ๐ก"
Aur tab se Guddu ka laptop automatic restart hone lagal... bhoot vs code! ๐ป
๐ Internal Blog Links:
- ๐ C++ If-Else Statement – Jab Man Kahe Haan, Dimaag Kahe Naa
- ๐ C++ Logical Operators – Sweety Ka Loyalty Test
- ๐ C++ Loops – Karna Ji Ki Kasam 'Jab Tak Suraj Na Dube'!
๐ External SEO Links:
- ๐ GeeksforGeeks – Ternary Operator in C++
- ๐ง StackOverflow – How Ternary Works
- ๐ Medium – Ternary Operator Simplified
๐ฎ Agla Vishay (Next Topic Suggestion):
๐งจ "C++ Loops – Jab Karna Ne Kasam Kha Li: 'Jab Tak Suraj Na Dube, Hum Try Karte Rahb!'"
For loop, while loop, do-while – mythological kasam ke sang! Likh dein? ๐

No comments:
Post a Comment