Which C++ feature automatically manages dynamically allocated objects and reduces the need for explicit delete statements?

Options

  • A. Smart pointers
  • B. Preprocessor macros
  • C. Namespaces
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. Smart pointers

Detailed Explanation

Answer: Smart pointers

Smart pointers are library types that help manage dynamically allocated objects automatically.

Common smart pointers include unique_ptr, shared_ptr and weak_ptr.

They work with object lifetime and RAII, reducing the need for manually writing delete and helping prevent common memory-management problems.