Assume we have an expression like
(x > 5)
in C language. Is there any guarantee given by the language / standard that the expression will be evaluated to 0
when it's false and to 1
when it's true?
Yes, it is guaranteed by the standard.
As per the C11
standard document, chapter 6.5.8, paragraph 6, [Relational operators]
Each of the operators
<
(less than),>
(greater than),<=
(less than or equal to), and>=
(greater than or equal to) shall yield1
if the specified relation istrue
and0
if it isfalse
. The result has typeint
.
Update: Same chapter and paragraph for C99
standard also.
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