Owning
With new and delete you must remember every delete yourself. A smart pointer is a small object on the stack that owns a heap object. When the smart pointer is destroyed, its destructor deletes what it owns. This is RAII.
One owner
std::make_unique<int>(7) puts an int holding 7 on the heap and returns a std::unique_ptr that owns it. a lives on the stack and keeps the address, 0x5a10. *a reads the 7, like a raw pointer. You never write new.
auto b = a; would not compile: unique_ptr's copy constructor is deleted. A copy would give two owners, and both would delete the same int at the end, a double delete. One owner, always.
So line 5 moves instead. b takes the address 0x5a10 and becomes the owner; a is left holding nullptr and owns nothing. The int on the heap does not move or change. Only the ownership moved.
Shared owners
std::make_shared<int>(5) puts the int 5 on the heap together with a control block. The control block keeps the use count: how many shared_ptrs own the int. s is the first owner, so the count is 1.
A shared_ptr can be copied. auto t = s; gives t the same address, 0x5a40, and adds 1 to the use count. Now s and t both own the same int, and the count is 2.
s.use_count() reads the number in the control block. Line 9 prints 2: two shared_ptrs, s and t, own the int. Neither one alone decides when the int is deleted.
At the inner closing brace t goes out of scope and its destructor runs. It subtracts 1 from the use count: 2 becomes 1. The count is not 0, so the int stays. s still owns it.
Line 11 prints 1. Only s owns the int now. The memory stays reserved exactly as long as at least one owner is alive, and there is still no delete anywhere in the code.
Cleaning up
At main's closing brace the locals are destroyed in reverse order: s, then b, then a. s drops the count to 0 and deletes the int 5 and its control block. b deletes the 7. a owns nothing. No leak.
Reach for unique_ptr first: one owner, and usually no more cost than a raw pointer. Use shared_ptr only when several parts must keep one object alive. std::weak_ptr watches a shared object without owning it, which breaks reference cycles.
What happens
;; step 1/11 · owner
raw pointer: int* p = new int(7);
... you must write delete p; on every path
smart pointer: an object that OWNS the heap object
its destructor deletes it for you
#include <memory> gives std::unique_ptr, std::shared_ptr
RAII: a resource is tied to an object's lifetime
The addresses 0x5a10, 0x5a30 and 0x5a40 are made up and short so they fit. Real ones are longer, change from run to run, and the layout of the control block is up to the library. std::make_shared usually puts the object and its control block in one allocation; the standard recommends this and the common libraries (libstdc++, libc++, MSVC) do it. std::shared_ptr<int>(new int(5)) needs at least two.