Which C++ smart pointer provides exclusive ownership of a dynamically allocated object?
Options
- A. shared_ptr
- B. weak_ptr
- C. unique_ptr
- D. More than one of the above
- E. None of the above
Quiz Practice:
C. unique_ptr
Answer: unique_ptr
std::unique_ptr represents exclusive ownership of a dynamically allocated object.
Normally, only one unique_ptr owns the object at a time. When the owning unique_ptr is destroyed, the managed object is automatically released.
This helps reduce manual memory-management errors.