Presentation is loading. Please wait.

Presentation is loading. Please wait.

How Dynamic Memory Works with Memory Diagram

Similar presentations


Presentation on theme: "How Dynamic Memory Works with Memory Diagram"— Presentation transcript:

1 How Dynamic Memory Works with Memory Diagram
CSCE 121 J. Michael Moore

2 output identifier stack heap

3 output identifier stack heap
int main() { int i = 14; int* k = &i; k = new int(3); delete k; Date* w = new Date(7, 7, 2015); delete w; w = nullptr; } w k i 14 identifier stack heap

4 output identifier stack heap
int main() { int i = 14; int* k = &i; k = new int(3); delete k; Date* w = new Date(7, 7, 2015); delete w; w = nullptr; } w k i 14 identifier stack heap

5 output identifier stack heap
int main() { int i = 14; int* k = &i; k = new int(3); delete k; Date* w = new Date(7, 7, 2015); delete w; w = nullptr; } w 3 k i 14 identifier stack heap

6 output identifier stack heap
int main() { int i = 14; int* k = &i; k = new int(3); delete k; Date* w = new Date(7, 7, 2015); delete w; w = nullptr; } w 3 k i 14 identifier stack heap

7 class Date { int month; int day; int year; public: // constructors Date(); Date(int month, int day, int year); // accessors and mutators int getMonth(); void setMonth(int month); int getDay(); void setDay(int Day); int getYear(); void setYear(int year); // methods void printDate(); };

8 output identifier stack heap
int main() { int i = 14; int* k = &i; k = new int(3); delete k; Date* w = new Date(7, 7, 2015); delete w; w = nullptr; } month 7 day 7 year 2015 w 3 k i 14 identifier stack heap

9 output identifier stack heap
int main() { int i = 14; int* k = &i; k = new int(3); delete k; Date* w = new Date(7, 7, 2015); delete w; w = nullptr; } month 7 day 7 year 2015 w 3 k i 14 identifier stack heap

10 output identifier stack heap
int main() { int i = 14; int* k = &i; k = new int(3); delete k; Date* w = new Date(7, 7, 2015); delete w; w = nullptr; } month 7 day 7 year 2015 w 3 k Dangling Pointer i 14 identifier stack heap


Download ppt "How Dynamic Memory Works with Memory Diagram"

Similar presentations


Ads by Google