try code and image side by side

This commit is contained in:
Jidong Xiao
2023-09-18 21:52:39 -04:00
parent 9ba344c583
commit 53080f3930

View File

@@ -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.
Heres a simple example involving dynamic allocation of integers:
<table>
<tr>
<td>
```cpp
int * p = new int;
*p = 17;
@@ -42,6 +45,11 @@ cout << *p << " " << *q << endl;
delete p;
delete q;
```
</td>
<td><img src="heap.png" alt="heap"</td>
</tr>
</table>
<!--[alt text](heap.png "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