Q. What will be the output of the following Rust code?

Code:
fn main() {
    let x = 5;
    let y = x;
    println!("{}", x);
}
  • (A) 5
  • (B) Compilation error
  • (C) Undefined behavior
  • (D) 0
πŸ’¬ Discuss
βœ… Correct Answer: (A) 5
Explanation: Since x is a primitive type (Copy trait), y gets a copy and x remains valid. Output is 5.
Explanation by: Admin
Since x is a primitive type (Copy trait), y gets a copy and x remains valid. Output is 5.

πŸ’¬ Discussion


πŸ“Š Question Analytics

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