Which smart pointer in C++ retains shared ownership of an object through a pointer? 

  • auto_ptr 
  • unique_ptr 
  • weak_ptr 
  • shared_ptr
shared_ptr is a type of smart pointer in C++ that retains shared ownership of an object. This means multiple shared_ptr objects can own the same object, and the object will only be destroyed when the last shared_ptr owning it is destroyed or reset. This helps in preventing memory leaks and ensuring safer memory management.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *