🎙 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 7 of 10

How do you hand ownership from one uniqueptr to another?

How do you hand ownership from one unique_ptr to another?

  1. A.unique_ptr<T> q = p;
  2. B.unique_ptr<T> q = std::move(p);
  3. C.unique_ptr<T> q = p.get();
  4. D.unique_ptr<T> q = &p;
Answer & explanation

Correct answer: unique_ptr<T> q = std::move(p);

unique_ptr cannot be copied; moving transfers ownership and leaves p empty.

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 →