Skip to content

Commit

Permalink
Smart pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhruv1503 authored Jun 27, 2024
1 parent 0b536af commit 9d11a18
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions problem-of-the-day/day26/dev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# C++ Smart Pointers

## Introduction
Smart pointers are a feature of C++ that allows for more robust memory management. They ensure automatic and appropriate destruction of dynamically allocated memory, preventing memory leaks and other common memory management errors.

## Types of Smart Pointers
- `unique_ptr`: Allows exactly one owner of the underlying pointer.
- `shared_ptr`: Allows multiple owners of the same pointer; the pointer is destroyed when the last owner goes out of scope.
- `weak_ptr`: Complements `shared_ptr` by holding a non-owning reference to an object that is managed by `shared_ptr`.

## Benefits
- Automatic memory management.
- Prevention of memory leaks.
- Can be used to implement sophisticated data structures like linked lists, graphs etc!

## Resources
- [C++ Smart Pointers - cppreference.com](https://en.cppreference.com/w/cpp/memory)
- [Smart Pointers in C++ - GeeksforGeeks](https://www.geeksforgeeks.org/smart-pointers-cpp/)
- [Understanding Smart Pointers in C++ - YouTube](https://www.youtube.com/watch?v=UOB7-B2MfwA)

## Conclusion
Understanding and utilizing smart pointers effectively can greatly enhance your C++ programming skills and contribute to writing clean, efficient, and safe code.

0 comments on commit 9d11a18

Please sign in to comment.