C++Tutorial for Beginners 46 - The New Operator; Allocating Memory in C++

The "new" operator in C++ allows us to allocate memory. This is the source of a lot of C++'s power; we can explicitly allocated the amount of memory we need, and refer to it using pointers.

On the other hand, it's also a source of a lot of memory leaks in C++ programs, since it's easy to forget that you've got to free that memory later. You can free memory with "delete", you've got to call the right version of delete depending on whether you're freeing memory just for one object, or for a whole array of values.





Click here to download source code for this tutorial.