#include<iostream>
using namespace std;
class car
{
string name;
int num;
public:
car(string a, int n)
{
cout << "Constructor called" << endl;
this->name = a;
this->num = n;
}
void enter()
{
cin >> name;
cin >> num;
}
void display()
{
cout << "Name: " << name << endl;
cout << "Num: " << num << endl;
}
};
int main()
{
// Using new keyword
car *p = new car("Honda", 2017);
p->display();
}
why don't we deallocate space for 'car *p'? If we don't deallocate memory space on the heap, won't there be a memory leak? I am a newbie trying to learn c++. I had read that I always had to deallocate space after allocating on heap... I found this code online