πŸ“Š Rust
Q. What is the ownership model in Rust primarily designed to prevent?
  • (A) Syntax errors
  • (B) Memory leaks and data races
  • (C) Slow compilation
  • (D) Infinite loops
πŸ’¬ Discuss
βœ… Correct Answer: (B) Memory leaks and data races

Explanation: Rust's ownership model ensures memory safety without a garbage collector, preventing memory leaks and data races.

πŸ“Š Rust
Q. Which keyword is used to define an immutable variable in Rust?
  • (A) let
  • (B) mut
  • (C) const
  • (D) var
πŸ’¬ Discuss
βœ… Correct Answer: (A) let

Explanation: In Rust, 'let' defines an immutable variable by default. 'mut' is used to make it mutable.

πŸ“Š Rust
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.

πŸ“Š Rust
Q. Which trait must be implemented to allow a struct to be printed using println! with {:?}?
  • (A) Display
  • (B) Debug
  • (C) Clone
  • (D) Copy
πŸ’¬ Discuss
βœ… Correct Answer: (B) Debug

Explanation: The {:?} formatter requires the Debug trait to be implemented for the type.

πŸ“Š Rust
Q. What does the 'unwrap()' method do in Rust?
  • (A) Returns a default value
  • (B) Converts a string to an integer
  • (C) Extracts the value from an Option or Result, panicking if it's None or Err
  • (D) Ignores errors silently
πŸ’¬ Discuss
βœ… Correct Answer: (C) Extracts the value from an Option or Result, panicking if it's None or Err

Explanation: unwrap() retrieves the value inside an Option or Result, but panics if it's None or Err.

πŸ“Š Rust
Q. Which keyword is used to define a mutable variable in Rust?
  • (A) let
  • (B) mut
  • (C) var
  • (D) change
πŸ’¬ Discuss
βœ… Correct Answer: (B) mut

Explanation: Rust uses 'mut' to make a variable mutable; 'let' alone creates an immutable variable.

πŸ“Š Rust
Q. What is the default behavior of variables in Rust?
  • (A) Mutable
  • (B) Global
  • (C) Immutable
  • (D) Static
πŸ’¬ Discuss
βœ… Correct Answer: (C) Immutable

Explanation: Variables in Rust are immutable by default unless explicitly marked with 'mut'.

πŸ“Š Rust
Q. Which of the following is a valid way to define a function in Rust?
  • (A) function my_func() {}
  • (B) def my_func() {}
  • (C) fn my_func() {}
  • (D) func my_func() {}
πŸ’¬ Discuss
βœ… Correct Answer: (C) fn my_func() {}

Explanation: Rust uses the 'fn' keyword to define functions.

πŸ“Š Rust
Q. What does the 'match' keyword do in Rust?
  • (A) Compares two strings
  • (B) Pattern matching
  • (C) Loops over a collection
  • (D) Defines a macro
πŸ’¬ Discuss
βœ… Correct Answer: (B) Pattern matching

Explanation: 'match' is used for pattern matching, similar to switch statements in other languages.

πŸ“Š Rust
Q. Which trait allows a type to be duplicated in Rust?
  • (A) Clone
  • (B) Copy
  • (C) Debug
  • (D) Display
πŸ’¬ Discuss
βœ… Correct Answer: (A) Clone

Explanation: The 'Clone' trait allows for explicit duplication of values.