Pointers and Memory Management Interview Questions for C++
26 Pointers and Memory Management questions with answers for c++ roles — 7 easy, 13 medium, 6 hard.
About Pointers and Memory Management
Understand stack and heap memory, raw pointers, references, pointer arithmetic, new and delete, and why leaks and dangling pointers happen. Then learn RAII and smart pointers such as unique_ptr, shared_ptr and weak_ptr, plus alignment, custom deleters and memory pools used in performance-critical systems.
What is the difference between stack and heap memory?
Show answer
What is a dangling pointer?
Show answer
What is pointer arithmetic?
Show answer
What is the difference between delete and delete[]?
Show answer
What is a void pointer and when would you use it?
Show answer
Find the middle node of a linked list in a single pass.
Show answer
What is a memory leak and how do you detect one?
Show answer
What is the difference between new/delete and malloc/free?
Show answer
What is RAII and why is it central to C++?
Show answer
Explain unique_ptr, shared_ptr and weak_ptr.
Show answer
Why should you prefer make_unique and make_shared over calling new directly?
Show answer
Two objects hold shared_ptr references to each other and their memory is never released. Why, and how do you fix it?
Show answer
What is the difference between const int*, int* const and const int* const?
Show answer
What is the difference between a shallow copy and a deep copy?
Show answer
Reverse a singly linked list using pointers.
Show answer
Your program crashes with the message double free or corruption. What could cause it?
Show answer
A function returns a reference to a local variable and the code sometimes works. Explain what is happening.
Show answer
Describe a time you improved code quality by changing how memory was managed.
Show answer
Write a function that allocates a 2D matrix safely without raw new and delete.
Show answer
Implement a minimal unique_ptr-like class.
Show answer
A production service's memory usage grows steadily over several days. How do you find the cause?
Show answer
What are memory alignment and padding?
Show answer
What is a custom deleter for a smart pointer and when do you need one?
Show answer
What are placement new and memory pools?
Show answer
Should a function take a shared_ptr by value, by const reference, or take a raw pointer or reference?
Show answer
Frequently asked questions
How important is Pointers and Memory Management in C++ interviews?
Understand stack and heap memory, raw pointers, references, pointer arithmetic, new and delete, and why leaks and dangling pointers happen. Then learn RAII and smart pointers such as unique_ptr, shared_ptr and weak_ptr, plus alignment, custom deleters and memory pools used in performance-critical systems.
How should I use the Pointers and Memory Management sheet?
Go top to bottom — easy to hard. Answer before opening each answer, tick what you solved and save misses to Last-Minute Revision.