Advertisement
Guest User

Why is this giving me a compile error

a guest
Jan 29th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.45 KB | None | 0 0
  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.     println!("{:p}", y);  // 0x7fff230091e8
  13.     println!("{:p}", *y); // 0x7fff230091e4
  14.     println!("{:p}", x);  // 0x7fff230091e4
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement