Question 4
Back to Exercise
p may be a null pointer. Which condition is safe?
- A p->count > 0 && p != NULL
- B p != NULL && p->count > 0 Correct
- C p != NULL & p->count > 0
- D Both orders are equally safe
Correct Answer: Option B
&& evaluates left to right and stops at the first false operand, so the NULL test must come first. The single & evaluates both sides and does not protect anything.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!