How do C++ operators work -
given x = 2, y = 1, , z = 0, following statement display?
printf("answer = %d\n", (x || !y && z));
it on quiz , got wrong, don't remember professor covering this, enlighten me please... know answer 1, why?
the expression interpreted x || (!y &&z)
(check out precedence of operators ||
, !
, &&
.
||
short-circuiting operator. if left operand true (in case of ||
) right side operand need not evaluated.
in case x
true, being boolean expression result 1.
edit.
the order of evaluation of &&
, ||
guaranteed left right.
Comments
Post a Comment