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.
Loading...
Related Quiz
- A function that calls itself directly or indirectly is known as a _______ function.
- In a function that needs to return multiple values, which method of parameter passing might be employed to facilitate this without using data structures like tuples or pairs?
- What is the impact of a function having a default argument?
- Which of the following statements about the struct and class keywords is true?
- If an exception is thrown and not caught anywhere in the program, function _______ is called.