The compiler applies these same type conversions when we use a value of one arithmetic type where a value of another arithmetic type is expected. For example, when we use a nonbool value as a condition (§ 1.4.1, p. 12), the arithmetic value is converted to bool in the same way that it would be converted if we had assigned that arithmetic value to a bool variable:
int i = 42;
if (i) // condition will evaluate as true
i = 0;
If the value is 0, then the condition is false; all other (nonzero) values yield true. By the same token, when we use a bool in an arithmetic expression, its value always converts to either 0 or 1. As a result, using a bool in an arithmetic expression is almost surely incorrect.
i couldn't understand what this part says nor what the code means
if anybody could help thank you very much
Aucun commentaire:
Enregistrer un commentaire