Logical AND (&&) and OR (||) operators

suggest change

These operators have the usual precedence in C++: AND before OR.

// You can drive with a foreign license for up to 60 days
bool can_drive = has_domestic_license || has_foreign_license && num_days <= 60;

This code is equivalent to the following:

// You can drive with a foreign license for up to 60 days
bool can_drive = has_domestic_license || (has_foreign_license && num_days <= 60);

Adding the parentheses does not change the behavior, though it does make the expression easier to read. The parentheses make the writer's intent clear.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents