Examples of new and delete
a = new int; // error, naturally
b = new int; // memory is allocated
delete b; // memory is deallocated
delete a; // error; a is not a pointer
array = new int[1000]; // allocate 1000 ints
for (int index = 0; index < 1000; index++)
delete[] array; // deallocate memory
- delete and delete[] (unfortunately) aren’t the same thing
- Note that sizeof() is done automatically, unlike malloc()
- Automatic variables (index) can be declared almost anywhere