How memory address is created in c++ while using the pointer ?
int *ptr1 = new int(10);
int *ptr2 = ptr1;
delete ptr2;
I understand that the heap memory is freed, and ptr1 becomes a dangling pointer because it still stores the old address.
But I’m confused about the address itself.
My questions are:
- Is the memory address itself created inside the heap?
- When we call
delete, is the address removed or only the data at that address? - After memory is freed, can the same address later be reused for another variable?
- Where is the pointer variable stored, vs where is the actual heap memory stored?
I’m trying to understand the difference between:
- the pointer variable,
- the address value,
- and the actual heap memory block.”
u/Additional-Start661 — 8 days ago