In C, what does the logical AND operator do when its left operand is false?
Correct answer
B. It skips evaluating the right operand
13 views
B. It skips evaluating the right operand
13 views
Short-circuit evaluation means the left operand of the logical AND decides the result on its own: when it is false the right side is never evaluated, so a guard that tests a pointer for NULL before dereferencing it cannot crash. The logical OR mirrors this by skipping the right side when the left is true. Because the skipped expression never runs, any side effect inside it, such as a function call or an increment, silently never happens.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is B? Ask here and get an explanation.