I have written the demo
class. It allocated the array arr
dynamically. Do I need to write the default destructor ~demo
as shown in the code to free up the memory allocated to arr
or the default destructor does that itself?
#include <iostream>
using namespace std;
class demo
{
int *arr;
public:
demo(int n)
{
arr = new int[n];
}
~demo()
{
delete[] arr;
}
};
int main()
{
demo obj(10);
cout << "done\n";
return 0;
}