Rust MCQs with answers Page - 30

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

R

Ravina • 3.96K Points
Extraordinary

Q. What is a feature of trait objects?

  • (A) Compile-time dispatch
  • (B) Dynamic dispatch
  • (C) Type inference
  • (D) Stack allocation

R

Ravina • 3.96K Points
Extraordinary

Q. Which type must be used to allow mutation through shared references?

  • (A) Box<T>
  • (B) RefCell<T>
  • (C) Rc<T>
  • (D) Vec<T>

R

Ravina • 3.96K Points
Extraordinary

Q. Which method removes the last element of a vector?

  • (A) remove()
  • (B) delete()
  • (C) pop()
  • (D) truncate()

R

Ravina • 3.96K Points
Extraordinary

Q. Which trait allows custom cleanup logic for a type?

  • (A) Destructor
  • (B) Drop
  • (C) Clear
  • (D) Free

R

Ravina • 3.96K Points
Extraordinary

Q. Which syntax is correct for a function returning a Result?

  • (A) fn my_func() -> Result<String, i32>
  • (B) fn my_func() -> Option<String>
  • (C) fn my_func(String) -> Error
  • (D) fn my_func(Result)

R

Ravina • 3.96K Points
Extraordinary

Q. Which tool is used to build and run tests in Rust?

  • (A) rustup
  • (B) cargo test
  • (C) rustc
  • (D) cargo check

R

Ravina • 3.96K Points
Extraordinary

Q. Which macro is used to concatenate strings at compile time?

  • (A) format!
  • (B) concat!
  • (C) join!
  • (D) merge!

R

Ravina • 3.96K Points
Extraordinary

Q. What is the default behavior of panic! in Rust?

  • (A) Logs error and halts program
  • (B) Returns error
  • (C) Restarts system
  • (D) Ignores error

R

Ravina • 3.96K Points
Extraordinary

Q. Which method allows you to iterate over a vector and modify its elements?

  • (A) iter()
  • (B) into_iter()
  • (C) iter_mut()
  • (D) for_each()

R

Ravina • 3.96K Points
Extraordinary

Q. Which operator is used for logical AND in Rust?

  • (A) &
  • (B) &&
  • (C) and
  • (D) ##

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