Questions tagged [booleans]

For questions about booleans, a data type representing logical values, typically either true or false.

Filter by
Sorted by
Tagged with
20 votes
10 answers
4k views

What are the drawbacks of allowing implicit boolean/integer conversions?

Some languages (C, C++, JavaScript, Python) allow one to use integers as booleans and vice versa: int x; if (x) // Equivalent to: x != 0 y(); Or: ...
user16217248's user avatar
  • 7,535
9 votes
5 answers
1k views

How to make logical operators that return operands consistent in a statically typed language?

In C++, 3 || 4 returns true. But in Python, 3 or 4 returns 3 instead. That's a logical operator that returns its operand. I don'...
user23013's user avatar
  • 2,258
12 votes
6 answers
387 views

What are the disadvantages of this far-fetched idea: All integers can be treated as boolean arrays?

I do not know of any languages that support this idea but I just thought that since numbers are just bits, why should we not be able to access those bits directly? In most languages such as C or C++, ...
user16217248's user avatar
  • 7,535