If I have the following statement:
int *x = new int;
In this case, I allocate memory to the heap dynamically. In other words, I now have a reserved memory address for an int object.
After that, say that I did the following:
delete x;
This means that I freed up the memory address on the heap.
Let's say after that I did the following:
int *x = new int;
Will x point to the exact same old memory address that it was pointing to on the heap before it was deleted?
What if I did this before delete :
x = NULL;
And then did the following:
int *x = new int;
Will x indicate a memory address on the heap other than the old one?
Thanks.
c ++ heap new-operator memory-address dynamic-memory-allocation
Simplicity
source share