LearnFrenzy
Sign in Take a free test

Decision Making · Decision Making MCQ · Question 4

Which condition is safe when p may be NULL? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links