LearnFrenzy
Sign in Take a free test

Smart Pointers · Smart Pointers MCQ · Question 15

unique_ptr for a dynamic array Answer, explanation & discussion

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

Which smart pointer correctly owns new int[100]?

  • A std::unique_ptr<int>
  • B std::unique_ptr<int[]> (it calls delete[]) Correct
  • C std::weak_ptr<int>
  • D Any of them
Correct Answer: Option B

unique_ptr<int> would call delete instead of delete[] – undefined behaviour.

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