Loading…
december code / try / rust
No account needed. Answer, see why, move on.
Problem
What happens when this Rust code is compiled and run?
let s1 = String::from("hi"); let s2 = s1; println!("{} {}", s1, s2);
It does not compile: the String moved from s1 to s2, so s1 can no longer be used
It prints hi hi, because let s2 = s1 copies the string's text into s2 and leaves s1 as it was
It prints hi, then an empty string, because s1 is left empty by the move
It compiles, but panics at run time because s1 is empty after the move to s2
Nothing here is saved. Create a free account to keep your progress, take an assessment and get your readiness score.