Rust MCQs with answers Page - 14

Here, you will find a collection of MCQ questions on Rust. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 832.27K Points
Coach

Q. What does `Vec::new()` return?

  • (A) An empty array
  • (B) An empty string
  • (C) An empty vector
  • (D) A null value

A

Admin • 832.27K Points
Coach

Q. What happens when you try to use a moved value in Rust?

  • (A) Compiler error
  • (B) Runtime warning
  • (C) It returns None
  • (D) It clones the value

A

Admin • 832.27K Points
Coach

Q. What is the result of `let x = String::from("hi"); let y = x;`?

  • (A) `x` is cloned
  • (B) `x` and `y` share ownership
  • (C) `x` is moved to `y`
  • (D) Both `x` and `y` are dropped

A

Admin • 832.27K Points
Coach

Q. Which keyword defines an enumeration in Rust?

  • (A) enum
  • (B) union
  • (C) struct
  • (D) choice

A

Admin • 832.27K Points
Coach

Q. Which function creates a thread in Rust?

  • (A) thread::start
  • (B) std::thread::spawn
  • (C) new_thread()
  • (D) async_thread()

A

Admin • 832.27K Points
Coach

Q. Which trait is automatically implemented when using `#[derive(Clone)]`?

  • (A) Copy
  • (B) Clone
  • (C) Eq
  • (D) Debug

A

Admin • 832.27K Points
Coach

Q. What will happen if you try to mutate a borrowed immutable variable?

  • (A) It will compile but crash at runtime
  • (B) It will compile and succeed
  • (C) It will panic
  • (D) It will cause a compile-time error

A

Admin • 832.27K Points
Coach

Q. Which keyword is used to implement a trait for a type?

  • (A) interface
  • (B) trait
  • (C) impl
  • (D) use

A

Admin • 832.27K Points
Coach

Q. Which function would you use to create a `Result` that is always `Ok`?

  • (A) Result::new()
  • (B) Ok()
  • (C) Some()
  • (D) wrap_ok()

A

Admin • 832.27K Points
Coach

Q. Which of the following best describes the `Copy` trait in Rust?

  • (A) Enables heap allocation
  • (B) Allows shallow copy via assignment
  • (C) Used for deep cloning
  • (D) Implements runtime checks