The type of the expression required in the if
condition is boolean. The expression intVar!=0
is already boolean, the expression intVar
has type int
and requires an implicit conversion to boolean. As it happens the conversion rules for int
to bool
are precisely that anything non-zero maps to true
and zero maps to false
, so the resultant expression evaluation is exactly the same.
Sometimes writing the full intVar!=0
can add clarity (for example, to make it clear you're not evaluating a pointer type for nullptr
but rather an integral type for zero), whereas other times it doesn't - it really depends on the context.
Regarding requested references, I will use the standard. The section relating to conversions [conv.bool]:
4.14 Boolean conversions
A prvalue of arithmetic, unscoped enumeration, pointer, or pointer to member type can be converted to a
prvalue of type bool. A zero value, null pointer value, or null member
pointer value is converted to false; any other value is converted to
true