Differentiate smart pointers and raw pointers
Company: Qube
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: hard
Interview Round: Technical Screen
In C++:
- What is the difference between a **raw pointer** and a **smart pointer**?
- Compare common smart pointers (**`std::unique_ptr`**, **`std::shared_ptr`**, **`std::weak_ptr`**) in terms of ownership, lifetime management, and performance.
- Give examples of when you would use each, and common pitfalls to avoid (e.g., double free, leaks, cycles).
Quick Answer: This question evaluates a candidate's understanding of C++ pointer semantics, ownership models, lifetime management, and memory-safety trade-offs between raw and smart pointers.