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 parenthesis does not change the behavior, though, it does make it easier to read. By adding these parentheses, no confusion exist about the intent of the writer.

Feedback about page:

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


Operator precedence:
* Logical AND (&&) and OR (||) operators

Table Of Contents
3 Operator precedence
8 Arrays
11 Loops
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
84 RTTI
87 Scopes
104 Profiling
107 Recursion
117 Iteration
125 Alignment
134 Semaphore
136 Debugging
139 Mutexes
142 decltype