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
πŸ’¬ Discuss
βœ… Correct Answer: (B) Compilation error
Explanation: Ownership of 's' is moved to 't', so 's' is no longer valid.
Explanation by: Admin
Ownership of 's' is moved to 't', so 's' is no longer valid.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
62
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Admin
Publisher
πŸ“ˆ
97%
Success Rate