CAVEATS:
We are assuming 0x000 is a valid address.
Pointers are 8 bytes, this is a 64 bit machine.
I forget which way the stack grows and so I'm doing it upwards, i think it's downwards on x86 but whatever.
Execute:
let mut x = 1;
Memory:
| name | location | type | value |
|---|---|---|---|
| x | 0x000 | i32 | 1 |
Execute:
let y = &mut x;
Memory:
| name | location | type | value |
|---|---|---|---|
| x | 0x000 | i32 | 1 |
| y | 0x004 | &mut i32 | 0x000 |
Execute:
let z = *y;
Memory:
| name | location | type | value |
|---|---|---|---|
| x | 0x000 | i32 | 1 |
| y | 0x004 | &mut i32 | 0x000 |
| z | 0x00C | i32 | 1 |
Execute:
let a = &z;
Memory:
| name | location | type | value |
|---|---|---|---|
| x | 0x000 | i32 | 1 |
| y | 0x004 | &mut i32 | 0x000 |
| z | 0x00C | i32 | 1 |
| a | 0x00F | &i32 | 0x00C |