🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Memory and Smart Pointers: all 10 questions

Quiz: Memory and Smart Pointers · Question 9 of 10

Why prefer makeunique<Student() over uniqueptr<Student(new Student())?

Why prefer make_unique<Student>() over unique_ptr<Student>(new Student())?

  1. A.make_unique creates a shared object
  2. B.It avoids writing new at all, so there is no raw pointer that could leak
  3. C.make_unique is the only way to create a unique_ptr
  4. D.It makes the object constant
Answer & explanation

Correct answer: It avoids writing new at all, so there is no raw pointer that could leak

Code without raw new and delete is easier to keep leak-free.

Can you get the rest right without peeking?

Take the timed Quiz: Memory and Smart Pointers quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →