unique_ptr versus shared_ptr?
Simple meaning
Unique_ptr is exclusive ownership, zero overhead, move-only.
Open the full page for Why, Steps, Example and Key takeaway.
Panel-ready C++ interview set questions for freshers and experienced developers. Practice at Coding Cadre in Faridabad, or Online from Delhi NCR.
Unique_ptr is exclusive ownership, zero overhead, move-only.
Open the full page for Why, Steps, Example and Key takeaway.
To break shared_ptr cycles, like parent-child observers.
Open the full page for Why, Steps, Example and Key takeaway.
A move constructor steals resources from an rvalue so we copy pointers, not buffers.
Open the full page for Why, Steps, Example and Key takeaway.
The compiler generates a function per type I call it with.
Open the full page for Why, Steps, Example and Key takeaway.
Two bases share a grand-base, so a derived object would get two copies of the grand-base.
Open the full page for Why, Steps, Example and Key takeaway.
A per-class table of function pointers for virtual methods.
Open the full page for Why, Steps, Example and Key takeaway.
Realloc or insert can move elements, so old iterators and pointers dangle.
Open the full page for Why, Steps, Example and Key takeaway.
An anonymous function object.
Open the full page for Why, Steps, Example and Key takeaway.
The basic guarantee leaves the program valid
Open the full page for Why, Steps, Example and Key takeaway.
Malloc is C, no constructors, returns void pointer.
Open the full page for Why, Steps, Example and Key takeaway.
Substitution failure is not an error: a bad template candidate is dropped instead of failing the whole program.
Open the full page for Why, Steps, Example and Key takeaway.
Two threads access the same memory, at least one writes, with no happens-before.
Open the full page for Why, Steps, Example and Key takeaway.
A function or variable can be defined only once in the program, with exceptions for inline and templates.
Open the full page for Why, Steps, Example and Key takeaway.
Sequential vector access beats pointer chasing in a list or tree.
Open the full page for Why, Steps, Example and Key takeaway.
If I need a CRUD web app and a GC, C# is faster to ship.
Open the full page for Why, Steps, Example and Key takeaway.
A pointer holds an address and can be reseated or null.
Open the full page for Why, Steps, Example and Key takeaway.
Stack allocates automatic locals and frees them when the scope ends.
Open the full page for Why, Steps, Example and Key takeaway.
Virtual enables dynamic dispatch so a base pointer can call the derived override.
Open the full page for Why, Steps, Example and Key takeaway.
unique_ptr and shared_ptr manage lifetime automatically so I rarely call delete.
Open the full page for Why, Steps, Example and Key takeaway.
vector is contiguous, cache-friendly, and great for random access.
Open the full page for Why, Steps, Example and Key takeaway.