Conditional (Ternary) Operator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Conditional (Ternary) Operator

can anyone explain me in easy way

22nd Apr 2017, 2:05 PM
🎆Sourav Subhakant Dash🔥🔥
🎆Sourav Subhakant Dash🔥🔥 - avatar
3 Answers
+ 3
its pretty much a shortened if else int x = 0; // initialize variable if (4 / 2 == 2) { x = 2; } else { x = 5; } ...is the same as this... int x = (4 / 2 == 2) ? 2 : 5;
22nd Apr 2017, 4:33 PM
Edward
+ 2
please, check this code snippet which shows an interesting example of using ternary operators :) https://code.sololearn.com/c44AESqjw5e5/?ref=app
19th May 2017, 3:36 PM
Aibek T.
Aibek T. - avatar
0
output = condition? "true" : "false";
22nd Apr 2017, 2:18 PM
Calviղ
Calviղ - avatar