Rust MCQs with answers Page - 16

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. Which type in Rust can be used to handle operations that might fail?

  • (A) Option<T>
  • (B) Error<T>
  • (C) Try<T>
  • (D) Result<T, E>

A

Admin • 832.27K Points
Coach

Q. What does the `unwrap()` method do on a Result or Option?

  • (A) Returns a default value
  • (B) Prints the value
  • (C) Returns the value or panics if it's an error or None
  • (D) Ignores the value

A

Admin • 832.27K Points
Coach

Q. Which of these is a zero-cost abstraction in Rust?

  • (A) Smart pointers
  • (B) Traits
  • (C) Closures
  • (D) All of the above

A

Admin • 832.27K Points
Coach

Q. What happens when two mutable references exist simultaneously in Rust?

  • (A) Compile-time error
  • (B) One is dropped
  • (C) Both succeed
  • (D) Runtime panic

A

Admin • 832.27K Points
Coach

Q. Which operator is used to pattern match in Rust?

  • (A) =
  • (B) ->
  • (C) =>
  • (D) match

A

Admin • 832.27K Points
Coach

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

  • (A) An empty string
  • (B) A static string
  • (C) A null pointer
  • (D) A formatted string

A

Admin • 832.27K Points
Coach

Q. Which is the correct way to define a tuple in Rust?

  • (A) [1, 2]
  • (B) {1, 2}
  • (C) (1, 2)
  • (D) <1, 2>

A

Admin • 832.27K Points
Coach

Q. Which type of variable can be reassigned in Rust?

  • (A) let
  • (B) const
  • (C) mut
  • (D) static

A

Admin • 832.27K Points
Coach

Q. What is the purpose of `.expect()` in Rust?

  • (A) Ignores error silently
  • (B) Prints error and panics with custom message
  • (C) Retries the operation
  • (D) Always unwraps safely

A

Admin • 832.27K Points
Coach

Q. Which trait is required for a type to be formatted using {:?}?

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

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