Rust MCQs with answers Page - 8

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 • 833K Points
Coach

Q. Which module provides the HashMap collection in Rust?

  • (A) std::collections
  • (B) std::maps
  • (C) std::hashmap
  • (D) std::dict

A

Admin • 833K Points
Coach

Q. Which symbol is used to dereference a pointer in Rust?

  • (A) &
  • (B) #
  • (C) *
  • (D) @

A

Admin • 833K Points
Coach

Q. Which trait allows using the `+` operator for custom types?

  • (A) Clone
  • (B) Add
  • (C) Plus
  • (D) Append

A

Admin • 833K Points
Coach

Q. Which tool is used to run Rust tests?

  • (A) cargo check
  • (B) rustc test
  • (C) cargo test
  • (D) cargo run --test

A

Admin • 833K Points
Coach

Q. Which of the following is true about the `Box<T>` type?

  • (A) Stores data on the stack
  • (B) Provides multiple ownership
  • (C) Allocates data on the heap
  • (D) Is a primitive type

A

Admin • 833K Points
Coach

Q. What does `pub` keyword do in Rust?

  • (A) Marks a variable as public
  • (B) Makes the item accessible from outside its module
  • (C) Declares an external crate
  • (D) Indicates test code

A

Admin • 833K Points
Coach

Q. Which macro is used to create a vector with repeated elements?

  • (A) vec![x; n]
  • (B) repeat_vec!(x, n)
  • (C) make_vec(x, n)
  • (D) vec_repeat!(x, n)

A

Admin • 833K Points
Coach

Q. What does `unwrap_or_else()` accept as an argument?

  • (A) A direct value
  • (B) An Option
  • (C) A function or closure
  • (D) A macro

A

Admin • 833K Points
Coach

Q. Which is a trait used to convert a value into a string?

  • (A) Clone
  • (B) Display
  • (C) From
  • (D) ToString

A

Admin • 833K Points
Coach

Q. Which of these allows borrowing data mutably in Rust?

  • (A) &data
  • (B) &mut data
  • (C) mut &data
  • (D) *data

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