Rust MCQs with answers Page - 22

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

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. What happens if an Option is None and unwrap() is called?

  • (A) Returns 0
  • (B) Returns default
  • (C) Panics at runtime
  • (D) Ignores the value

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which keyword begins a loop that runs forever?

  • (A) while true
  • (B) loop
  • (C) for
  • (D) repeat

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. What is the effect of shadowing in Rust?

  • (A) Overwrites memory
  • (B) Disables the previous variable
  • (C) Reuses the variable name with a new value
  • (D) Deletes the variable

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which keyword is used to break out of a loop?

  • (A) exit
  • (B) stop
  • (C) return
  • (D) break

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. What is the purpose of continue in loops?

  • (A) Ends the loop
  • (B) Skips current iteration
  • (C) Repeats the loop
  • (D) Starts a new loop

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which keyword is used to declare a module in Rust?

  • (A) package
  • (B) mod
  • (C) crate
  • (D) namespace

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which method is used to check if a vector contains an element?

  • (A) has()
  • (B) includes()
  • (C) contains()
  • (D) in()

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which keyword is used to handle both Result and Option conveniently?

  • (A) unwrap
  • (B) ?
  • (C) match
  • (D) ok

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which type must be used when working with recursive types?

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

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. What does the clone() method do?

  • (A) Copies a reference
  • (B) Moves the value
  • (C) Creates a deep copy of the value
  • (D) Deletes the value

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