TOPIC 16.2.2
Checking for Allocation Errors


The allocation of memory is checked in the same way we check to see if a file was opened correctly. An example is show below.

head_ptr = new country_node;

if(head_ptr == NULL)
{
    cerr << "New node was not created.";
}

This shows that if for some reason, new can not allocate memory, NULL is assigned to the pointer, in this case head_ptr. Most times the reason memory allocation will not occur is due to the fact there is no free memory available.