0

What does this statement do?

X=3, y=0; sout(++x > 4|| y-- > 0 ? ++y : --x);

1st May 2021, 4:36 AM
kreddyt
kreddyt - avatar
1 Answer
+ 3
Karthik Reddy Thotamgari ?: is known as ternary operator. It's a shortcut of if else statement. expression ? statement1 : statement2 if expression = true then statement1 will execute otherwise statement2 will execute. Here x = 3 ++x = 4 x = 4 y = 0 y-- = 0 y = -1 So here (4 > 4 || 0 > 0) is false so after colon --x will print but we have x = 4 because of ++x so here --x will be 3
1st May 2021, 5:15 AM
A͢J
A͢J - avatar