What is the primary reason for using smart pointers over raw pointers in modern C++?
- To increase execution speed
- To use less memory
- To look modern
- To manage memory automatically
Smart pointers, such as unique_ptr, shared_ptr, and weak_ptr, were introduced in C++ to provide automated memory management. They automatically handle the destruction of objects they point to, thereby preventing common issues like memory leaks and dangling pointers.
Loading...
Related Quiz
- To loop over each character in a string named myString, one could use for(_______ : myString).
- What is the purpose of the this pointer in C++?
- In what situation might explicit template specialization be used in C++?
- In C++, an abstract class can have a mix of abstract as well as _______ methods.
- When defining a struct in C++, what does the compiler implicitly provide?