3 ms·
In C, the && and || operators are short-circuiting. This works (in that it doesn't give a compiler error) because printf returns an int. I remember following
by kmill 5y ago
In C, the && and || operators are short-circuiting. This works (in that it doesn't give a compiler error) because printf returns an int.
I remember following a really old Python tutorial that suggested the way to write inline if/else statements was
C and A or B
which makes use of similar short-circuiting behavior. Nowadays this is written as
A if C else B
The and/or version depends on A being truthy, otherwise it evaluates both A and B, giving the value of B.