A

Admin • 833.24K Points
Coach

Q. What is the result of the following code?

Code:
fn main() {
let s = String::from("hello");
let t = s;
println!("{}", s);
}
  • (A) hello
  • (B) Compilation error
  • (C) Undefined behavior
  • (D) Nothing
  • Correct Answer - Option(B)
  • Views: 28
  • Filed under category Rust
  • Hashtags:

Explanation by: Admin

Ownership of 's' is moved to 't', so 's' is no longer valid.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.