What is the difference between std::unique_ptr, std::shared_ptr, and std::weak_ptr?

Last updated 21 June 2026

  • unique_ptr is sole ownership: move-only, pointer-sized, zero overhead, and the default choice.

  • shared_ptr is shared ownership via a control block with an atomic strong count. The object dies when the last owner releases.

  • weak_ptr observes a shared_ptr without keeping it alive. Use lock() to access it, ideal for back-references, caches, and breaking cycles.

  • https://www.geeksforgeeks.org/interview-prep/advanced-topics-design-patterns-interview-questions-c-programming/
  • https://github.com/25-masik-52/CppInterviewKit
All C++ interview questions