I guess the program will first find b && c, let's call it d, and then find a || d, right?
No.
First of all, operator precedence only affects grouping of operators and operands; it does not affect the order in which expressions are evaluated. In general, evaluation order is left unspecified; for example, in an expression like a + b * c
, each of a
, b
, and c
may be evaluated in any order. Similarly, b * c
must be evaluated before a + b * c
, but that doesn't mean that b * c
must be evaluated before a
.
The ||
and &&
operators are special in that they force left-to-right evaluation; the left-hand side will be fully evaluated (and all side effects applied) first. Also, both operators use "short-circuit" evaluation; if the value of the expression can be determined from the left-hand operand, then the right-hand operand won't be evaluated at all.
Since &&
has higher precedence than ||
, the expression will be parsed as a || (b && c)
, meaning the result of a
will be OR'd with the result of b && c
. However, since ||
and &&
force left to right evaluation, a
will be evaluated first. If the result of a
is 0, then b
will be evaluated. If the result of b
is non-zero, then c
will be evaluated. If b
is 0, then c
won't be evaluated. If a
is non-zero, then neither b
nor c
will be evaluated.
Here's a table showing the various possibilities; NZ means "non-zero", and NE means "not evaluated":
a b c b && c a || b && c
- - - ------ -----------
0 NZ NZ true (1) true (1)
0 NZ 0 false (0) false (0)
0 0 NE false (0) false (0)
NZ NE NE NE true (1)