Just to clarify I found similar answer but for C++, I'm kinda new to coding so I'm not sure whether it applies to C as well.
The boolean type. The bool represents a value, which could only be either true or false . If you cast a bool into an integer, true will be 1 and false will be 0.
C does not have boolean data types, and normally uses integers for boolean testing. Zero is used to represent false, and One is used to represent true. For interpretation, Zero is interpreted as false and anything non-zero is interpreted as true.
There are just two values of type bool: true and false. They are used as the values of expressions that have yes-or-no answers. C++ is different from Java in that type bool is actually equivalent to type int. Constant true is 1 and constant false is 0.
1 is considered to be true because it is non-zero. The fourth expression assigns a value of 0 to i. 0 is considered to be false.
More accurately anything that is not 0
is true.
So 1
is true, but so is 2
, 3
... etc.
You neglected to say which version of C you are concerned about. Let's assume it's this one:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
As you can see by reading the specification, the standard definitions of true
and false
are 1 and 0, yes.
If your question is about a different version of C, or about non-standard definitions for true
and false
, then ask a more specific question.
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