Re:First THINK C Program (2020)
by jhoechtl on Sunday August 15, 2021 @02:35PM
(#28191175)
Never saw something like this. A conditional execution without an if?
[ Parent
| on HN ]
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.