The main difference is that in an expression a && b
, b
will not be evaluated if a
is false, while in a & b
both a
and b
will be evaluated no matter what. One can say that &&
"short-circuits" the evaluation.
Similarly for a || b
: b
will not be evaluated if a
is true, while in a | b
both a
and b
will be evaluated no matter what.