Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- // New object
- let s = String::from("hello");
- // Reference to object
- let p = &s;
- // Override original object variable
- let s= 42;
- // Use reference
- func(p);
- // Print overwritten value: prints 42
- println!("{}", s);
- }
- fn func(y: &String) {
- // This prints "hello"
- println!("PRINT {}", y);
- }
- /**
- What happens to the String? Its owning variable is gone, is it not?
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement