AlgoMaster Logo

Dynamic Memory Allocation (new, delete)

Last Updated: May 17, 2026

13 min read

Sometimes you need an object that outlives the function that created it, or whose existence depends on a runtime decision. C++ gives you new to ask the runtime for fresh memory and delete to give it back. This chapter covers the basics of new and delete for a single object. Arrays (new[]/delete[]) come in the next chapter, the failure modes (leaks, dangling pointers, double-delete) get their own chapter after that, and smart pointers, which most modern code uses to wrap raw new, come later.

Premium Content

Subscribe to unlock full access to this content and more premium articles.