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.
Add your answer
Loading...

Leave a comment

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