Well, if you allocate memory dynamically, then you get a pointer, not the value itself.
int* a = new int;
Then you need to call delete and pass the pointer:
delete a;
If you try to assign a variable of type int b = *a; , then b will not be dynamically allocated. So you cannot write delete &b; , because b is allocated on the stack and will be automatically cleared when it goes out of bounds. If you assign it to a link similar to int& c = *a; , then you can write delete &c; but this is a bad error prone method because you have no guarantee that the memory referenced by c will be dynamically allocated.
Alexander Lapenkov
source share