Quote Originally Posted by A36
The first example crashed with an error that appears to be 'corruption of the heap'. If I set pointer 'y' to NULL before deleting it, the code ran fine. In the second example, the code ran with no errors. I can only surmise the first code crashed because it was storing an actual address, while in the second example it was 'empty'. Why that should matter I don't know since 'x's address wasn't moved to pointer 'y', just copied; 'x' should still be intact.
The first example's problem is that the pointer points to an object whose storage was not allocated via new. Therefore, using delete on it results in undefined behaviour, one symptom of which is a crash. When you set y to be a null pointer, this problem disappears because using delete on a null pointer is safe and results in no net effect.

The second example does not have the problem because the pointer points to an object whose storage was allocated via new, hence using delete is appropriate.