LearnFrenzy
Sign in Take a free test

Smart Pointers · Smart Pointers MCQ · Question 10

Deleting the pointer returned by get() Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 10 Back to Exercise

What happens if you delete p.get(); for a unique_ptr p?

  • A Nothing special
  • B Double delete (undefined behaviour) when p later deletes the same object Correct
  • C p becomes null
  • D Compile error
Correct Answer: Option B

get() returns a non-owning pointer; never delete it.

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