Rust MCQs with answers Page - 13

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 the `Default` trait provide?

  • (A) A way to clone values
  • (B) A default value for a type
  • (C) Formatted output
  • (D) Runtime error propagation

A

Admin • 832.27K Points
Coach

Q. Which method converts a `String` into a `&str`?

  • (A) .parse()
  • (B) .trim()
  • (C) .as_str()
  • (D) .to_str()

A

Admin • 832.27K Points
Coach

Q. Which trait is used for streaming output formatting?

  • (A) Debug
  • (B) Display
  • (C) Write
  • (D) Clone

A

Admin • 832.27K Points
Coach

Q. What does the `IntoIterator` trait do?

  • (A) Turns a collection into an iterator
  • (B) Sorts a collection
  • (C) Converts numbers to strings
  • (D) Clones collections

A

Admin • 832.27K Points
Coach

Q. Which function would you use to convert a string to an integer?

  • (A) str::as_i32()
  • (B) parse::<i32>()
  • (C) int::from_str()
  • (D) to_i32()

A

Admin • 832.27K Points
Coach

Q. What is the result of `let a = &5;` in Rust?

  • (A) Move the value 5
  • (B) Create a reference to 5
  • (C) Create a mutable reference
  • (D) Create a raw pointer

A

Admin • 832.27K Points
Coach

Q. Which keyword defines a module in Rust?

  • (A) mod
  • (B) module
  • (C) namespace
  • (D) use

A

Admin • 832.27K Points
Coach

Q. Which macro should you use to include code from another file?

  • (A) import!
  • (B) include!
  • (C) use!
  • (D) mod!

A

Admin • 832.27K Points
Coach

Q. Which of the following types guarantees at compile time that only one mutable reference exists?

  • (A) Rc<T>
  • (B) RefCell<T>
  • (C) &mut T
  • (D) Arc<T>

A

Admin • 832.27K Points
Coach

Q. What happens when a value goes out of scope in Rust?

  • (A) It is moved to the heap
  • (B) It is duplicated
  • (C) Its memory is automatically deallocated
  • (D) It becomes global

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ