Rust MCQs with answers Page - 21

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 does the .len() method return for a string or vector?

  • (A) Number of bytes
  • (B) Number of elements
  • (C) Memory address
  • (D) Last element

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which collection type maintains insertion order?

  • (A) HashMap
  • (B) HashSet
  • (C) Vec
  • (D) BTreeMap

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which method is used to create an iterator from a vector?

  • (A) .new()
  • (B) .clone()
  • (C) .iter()
  • (D) .map()

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. What does the keyword ref do in a match pattern?

  • (A) Creates a clone
  • (B) Creates a mutable reference
  • (C) Creates an immutable reference
  • (D) Performs recursion

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which function is used to sleep a thread?

  • (A) thread::delay()
  • (B) thread::sleep()
  • (C) std::wait()
  • (D) pause()

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which type is used for shared mutability?

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

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. What is the main goal of lifetimes in Rust?

  • (A) Runtime memory allocation
  • (B) Garbage collection
  • (C) Prevent dangling references
  • (D) Faster performance

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which of the following is a correct lifetime annotation?

  • (A) 'lifetime
  • (B) &'a str
  • (C) &str'a
  • (D) str:'a

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. What does the static keyword mean when used with a variable?

  • (A) Stored on the stack
  • (B) Thread-local value
  • (C) Value lives for the entire duration of the program
  • (D) Value can’t be mutated

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which keyword is used for asynchronous functions?

  • (A) await
  • (B) sync
  • (C) async
  • (D) concurrent

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