← 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?
- A.unique_ptr<T> q = p;
- B.unique_ptr<T> q = std::move(p);
- C.unique_ptr<T> q = p.get();
- 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 →