I have a co-worker that maintains that TRUE used to be defined as 0 and all other values were FALSE. I could swear that every language I've worked with, if you could even get a value for a boolean, that the value for FALSE is 0. Did TRUE used to be 0? If so, when did we switch?
In Python any non-zero integer value is true; zero is false.
For interpretation, Zero is interpreted as false and anything non-zero is interpreted as true. C++ is backwards compatible, so the C-style logic still works in C++. ( "true" is stored as 1, "false" as 0. )
Boolean Variables and Data Type ( or lack thereof in C ) For interpretation, Zero is interpreted as false and anything non-zero is interpreted as true.
Like in C, the integers 0 (false) and 1 (true—in fact any nonzero integer) are used.
The 0 / non-0 thing your coworker is confused about is probably referring to when people use numeric values as return value indicating success, not truth (i.e. in bash scripts and some styles of C/C++).
Using 0 = success allows for a much greater precision in specifying causes of failure (e.g. 1 = missing file, 2 = missing limb, and so on).
As a side note: in Ruby, the only false values are nil and false. 0 is true, but not as opposed to other numbers. 0 is true because it's an instance of the object 0.
It might be in reference to a result code of 0 which in most cases after a process has run, a result code of 0 meant, "Hey, everything worked fine, no problems here."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With