Let's look at f() + g() * h()
first.
Precedence and associativity defines what is an operand of what. For example, C operator precedence and associativity tells us that
f() + g() * h()
means
f() + ( g() * h() ) # * has higher precedence than +
rather than
( f() + g() ) * h() # If + had higher precedence than *
Notably, precedence doesn't determine the order in which operands are evaluated. In our example, the three functions could be called in any order, as long as the result of g()
and the result of h()
are multiplied together, and that the result of the multiplication is added to the result of f()
.
Back to
1 & 0 && ( d = 4 )
Precedence and associativity simply tell us that the above is equivalent to the following:
( 1 & 0 ) && ( d = 4 ) # & has higher precedence than &&
So what does this do?
&&
dictates that its right-hand side is only evaluated if its left-hand side is true. This is called short-circuit evaluation or short-circuiting.
1 & 0
is false, so d = 4
is never evaluated. This leaves d
unchanged, and thus uninitialized.