While loop with unsigned integer condition
4 answers
In this context, x
it must be converted to true
or false
.
From the C ++ 11 standard (4.12 / 1):
An arithmetic, unenumerated enumeration, pointer, or pointer to member type value can be converted to a prvalue of type
bool
. A null value, a null pointer value, or a null element pointer value is converted tofalse
; any other value is converted totrue
.
Think about
while (x){ ... }
and
while (x != 0){ ... }
+5
source to share