Boolean values: Difference between revisions

Content added Content deleted
(added ocaml, standard ml)
(added c)
Line 16:
 
QuickBasic has no keywords for true and false. Boolean expressions evaluate to 0 when false, and a non-zero value when true. Numbers also work in place of boolean expressions following those rules.
 
=={{header|C}}==
In C, a value which is equal to 0 is false, while a value which is not equal to 0 is true. Any of the following can be used:
* any integer type, where 0 gives false, and any other value gives true (note that in C, character types are also integer types, therefore this also applies to characters: the <code>'\0'</code> character is false)
* any floating point type, where again, 0 gives false and everything else gives true
* any enumeration type, again 0 gives false, anything else true
* any pointer type, where the null pointer gives false and any other pointer gives true
* in C99, the boolean type <code>bool</code> (defined in header <tt><stdbool.h></tt>), where <code>true</code> gives true and <code>false</code> gives false
* in C99, any [[Complex numbers|complex number]] type, where 0 (0 real and 0 imaginary) gives false, anything else gives true
 
=={{header|C++}}==
In C++, there are the constants <code>true</code> and <code>false</code> to represent those values. However, there are numerous implicit conversions to <code>bool</code>, therefore in conditions (and other contexts expecting boolean values), any of the following can be used:
* any integer type, where 0 converts to false, and any other value converts to true (note that in C++, character types are also integer types, therefore this also applies to characters: the <code>'\0'</code> character is false)
* any floating point type, where again, 0 gives false and everything else gives true
* any enumeration type, again 0 gives false, anything else true