Rust MCQs with answers Page - 15

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 `String::from("hello")` function do?

  • (A) Returns a static string
  • (B) Creates a new `&str`
  • (C) Creates a heap-allocated `String`
  • (D) Returns a `char`

A

Admin • 832.27K Points
Coach

Q. Which keyword is used to return a value from a function in Rust?

  • (A) exit
  • (B) ret
  • (C) return
  • (D) end

A

Admin • 832.27K Points
Coach

Q. What is the default behavior of Rust when accessing an index out of bounds in a vector?

  • (A) Returns None
  • (B) Panic at runtime
  • (C) Wraps around
  • (D) Returns -1

A

Admin • 832.27K Points
Coach

Q. Which Rust macro asserts that a condition is true?

  • (A) assume!
  • (B) expect!
  • (C) assert!
  • (D) check!

A

Admin • 832.27K Points
Coach

Q. What is the result of `Some(5).unwrap_or(10)`?

  • (A) 10
  • (B) 5
  • (C) None
  • (D) Error

A

Admin • 832.27K Points
Coach

Q. Which standard trait allows conversion from one type to another?

  • (A) From
  • (B) Convert
  • (C) Into
  • (D) Map

A

Admin • 832.27K Points
Coach

Q. Which function checks if a vector is empty?

  • (A) is_none()
  • (B) check()
  • (C) empty()
  • (D) is_empty()

A

Admin • 832.27K Points
Coach

Q. What is the result of the expression `vec![1, 2, 3].contains(&2)`?

  • (A) false
  • (B) true
  • (C) Error
  • (D) None

A

Admin • 832.27K Points
Coach

Q. Which macro is used to write formatted output to the console?

  • (A) printline!
  • (B) write!
  • (C) log!
  • (D) println!

A

Admin • 832.27K Points
Coach

Q. What is the main difference between `Box<T>` and `Rc<T>`?

  • (A) `Box` allows multiple ownership, `Rc` doesn't
  • (B) `Box` is for shared ownership, `Rc` is for unique ownership
  • (C) `Box` is for unique ownership, `Rc` is for shared ownership
  • (D) They are identical

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