Hey everyone.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int* ptr1 = new int;
int* ptr2 = ptr1;
delete ptr2; // Detroying ptr2
return 0;
}
In the above case will the memory used by ptr1 will be freed or just the ptr2 will be destroyed. I have one more doubt. I have a tree kind of structure in which the node is pointing to two children (These children have leaf nodes, Consider its a big tree). If I have to delete one child of the root node, Do I need to delete each pointer object of the grand children, grand grand children and so on? Thanks in advance?