Q. What is the purpose of lifetimes in Rust?

  • (A) To manage threads
  • (B) To track variable scope
  • (C) To ensure memory safety
  • (D) To define function signatures
πŸ’¬ Discuss
βœ… Correct Answer: (C) To ensure memory safety
Explanation: Lifetimes help Rust ensure references are valid and prevent dangling pointers.

Q. Which of the following types is used for optional values?

  • (A) Result
  • (B) Option
  • (C) Maybe
  • (D) Choice
πŸ’¬ Discuss
βœ… Correct Answer: (B) Option
Explanation: 'Option' is used to represent a value that may or may not be present.

Q. What is the output of this code?

Code:
fn main() {
    let x = 10;
    let y = &x;
    println!("{}", y);
}
  • (A) 10
  • (B) &10
  • (C) Compilation error
  • (D) Memory address
πŸ’¬ Discuss
βœ… Correct Answer: (A) 10
Explanation: Rust automatically dereferences references in println!, so it prints 10.

Q. Which of the following is true about Rust's memory management?

  • (A) Uses garbage collection
  • (B) Manual memory allocation
  • (C) Ownership and borrowing
  • (D) Reference counting only
πŸ’¬ Discuss
βœ… Correct Answer: (C) Ownership and borrowing
Explanation: Rust uses ownership and borrowing to manage memory safely without a garbage collector.

Q. What is the output of this code?

Code:
fn main() {
    let mut x = 5;
    x += 1;
    println!("{}", x);
}
  • (A) 5
  • (B) 6
  • (C) Compilation error
  • (D) Undefined
πŸ’¬ Discuss
βœ… Correct Answer: (B) 6
Explanation: The variable 'x' is mutable and incremented by 1, resulting in 6.