C++ delete a pointer (free memory)
The behaviour of your program is undefined. You can only use delete
on a pointer to memory that you have allocated using new
. If you had written
int* b = new int;
*b = 10;
int* c = b;
then you could write either delete b;
or delete c;
to free your memory. Don't attempt to derefererence either b
or c
after the delete
call though, the behaviour on doing that is also undefined.
The confusing part is that the answer to your question
Am I correct to understand in the last line, delete b and delete c are equivalent"
Is yes, they're equivalent, and both UB as mentioned everywhere else here.