From 53080f3930e2eaa6c6c097664db0326cb46ae5f3 Mon Sep 17 00:00:00 2001 From: Jidong Xiao Date: Mon, 18 Sep 2023 21:52:39 -0400 Subject: [PATCH] try code and image side by side --- lectures/06_memory/README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lectures/06_memory/README.md b/lectures/06_memory/README.md index 22cb1cf..0302bf9 100644 --- a/lectures/06_memory/README.md +++ b/lectures/06_memory/README.md @@ -21,11 +21,14 @@ static int counter; ## 6.2 Dynamic Memory Dynamic memory is: -- created using the new operator, +- created using the **new** operator, - accessed through pointers, and -- removed through the delete operator. +- removed through the **delete** operator. Here’s a simple example involving dynamic allocation of integers: + + + + +
```cpp int * p = new int; *p = 17; @@ -42,6 +45,11 @@ cout << *p << " " << *q << endl; delete p; delete q; ``` +heap +
+ - The expression new int asks the system for a new chunk of memory that is large enough to hold an integer and returns the address of that memory. Therefore, the statement int * p = new int; allocates memory