Advertisement
Guest User

Untitled

a guest
May 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. fn main() {
  2. // New object
  3. let s = String::from("hello");
  4.  
  5. // Reference to object
  6. let p = &s;
  7.  
  8. // Override original object variable
  9. let s= 42;
  10.  
  11. // Use reference
  12. func(p);
  13.  
  14. // Print overwritten value: prints 42
  15. println!("{}", s);
  16. }
  17.  
  18. fn func(y: &String) {
  19. // This prints "hello"
  20. println!("PRINT {}", y);
  21. }
  22.  
  23. /**
  24.  
  25. What happens to the String? Its owning variable is gone, is it not?
  26.  
  27. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement