| Found in | Example | |
|---|---|---|
| Dynamically Allocated | Heap | |
| Statically Allocated | Stack | int x = 10; |
int x;
int* p;
x = 7;
p = Null;
p = &x;
cout << *p << endl;
cout << p << endl;

malloc from C becomes new in C++
int* p = new int;
free from C becomes delete in C++
delete p;
Updating our student class from last time.
class student{
private:
string name;
int* grade;
public:
student();
student(int);
}
student:student(){
name = "";
grade = NULL;
}
student::student(int n){
grade = new int[n];
}
int main(){
student x(10);
return 0;
}

Question: we just returned and exited the program, but our memory on the heap is still out there. How can we solve this?