Let me focus on
What is bugging me is that I can't work out why this code works—I was amazed that it doesn't just throw an error.
Why do you think so? What happens is that we have
ybeing assigned an expression- that expression being an if
if() ... - leading to either a
TRUEorFALSEin the test - leading to either one of the two branches being entered
- leading to the respective code being evaluated
- leading to its final value being the value of the right-hand-side
- leading to this value being assigned to
y
Seems logical to me.