+ 5
Conditional (Ternary) Operator
can anyone explain me in easy way
3 ответов
+ 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;
+ 2
please, check this code snippet which shows an interesting example of using ternary operators :)
https://code.sololearn.com/c44AESqjw5e5/?ref=app
0
output = condition? "true" : "false";