Logical AND (&&) and OR (||) operators
suggest changeThese 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents