News for hackers. Stuff that matters.
Re:First THINK C Program (2020) by kmill on Sunday August 15, 2021 @03:15PM (#28191573)
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.

There are no comments on this comment yet.