Deleting Arrays

It's a common mistake to forget to delete an array:

char *SomePointer = new char[25];
delete SomePointer;

This will delete the zeroth element of SomePointer and leave the other 24 characters of the array taking up space in the heap. Eventually, there will be no more room in the heap, and the program will stop running. This is called a memory leak.

Get SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.