SHOW:
|
|
- or go back to the newest paste.
1 | fn main() { | |
2 | ||
3 | let x = &mut 5; | |
4 | //let y = &x; | |
5 | let y = &x; | |
6 | //*x = *x + 1; | |
7 | ||
8 | // y = is address where x is stored | |
9 | // y* = x = value of x = address where 5 is stored | |
10 | // y** = x* = 5 = literal i32 value 5 | |
11 | **y = **y + 5; // Giving compile error "error: cannot assign to data in a `&` reference" | |
12 | // Shouldn't the above line be fine since x is a reference to a mutable i32? | |
13 | println!("{:p}", y); // 0x7fff230091e8 | |
14 | println!("{:p}", *y); // 0x7fff230091e4 | |
15 | println!("{:p}", x); // 0x7fff230091e4 | |
16 | } |