← 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())?
- A.make_unique creates a shared object
- B.It avoids writing new at all, so there is no raw pointer that could leak
- C.make_unique is the only way to create a unique_ptr
- 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 →