Rust MCQs with answers Page - 27

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. Which loop construct in Rust always executes at least once?

  • (A) for
  • (B) while
  • (C) loop
  • (D) do-while

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which trait allows a type to be used with the `+` operator?

  • (A) PartialEq
  • (B) Ord
  • (C) Add
  • (D) Copy

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which macro is used to write to the standard error stream?

  • (A) println!
  • (B) eprint!
  • (C) debug!
  • (D) log!

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which keyword allows code that can break Rust’s safety guarantees?

  • (A) unsafe
  • (B) unchecked
  • (C) danger
  • (D) manual

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which method on an iterator returns true if all elements satisfy a predicate?

  • (A) any()
  • (B) none()
  • (C) filter()
  • (D) all()

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which function reads user input from the console?

  • (A) stdin().read_line()
  • (B) input()
  • (C) console.read()
  • (D) scan()

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. What does the drop() function do?

  • (A) Deletes a file
  • (B) Destroys a thread
  • (C) Explicitly destroys a value early
  • (D) Removes an element from a vector

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which method on a String adds a character to the end?

  • (A) add_char()
  • (B) insert()
  • (C) push()
  • (D) append()

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which method reverses a vector in place?

  • (A) rev()
  • (B) reverse()
  • (C) flip()
  • (D) invert()

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which of these types implements Copy by default?

  • (A) String
  • (B) Vec<i32>
  • (C) i32
  • (D) Box<i32>