Imagine you are maintaining a C++ application where memory leaks are a constant issue. Which type of pointer would be the best to use to ensure that dynamically allocated objects are properly deallocated? 

  • auto_ptr 
  • shared_ptr 
  • weak_ptr 
  • unique_ptr
unique_ptr is a smart pointer that retains sole ownership of an object. It ensures that there's only one unique_ptr pointing to the object, and it automatically deallocates the object once the unique_ptr goes out of scope.
Add your answer
Loading...

Leave a comment

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