Rust MCQs with answers Page - 28

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 trait is required to use a type in a HashMap key?

  • (A) Display
  • (B) Hash
  • (C) Clone
  • (D) Copy

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which keyword is used to create a lifetime parameter?

  • (A) lifetime
  • (B) &life
  • (C) 'a
  • (D) $life

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. What happens when a program uses an invalid reference?

  • (A) Compile-time error
  • (B) Silent failure
  • (C) Runtime warning
  • (D) Undefined behavior

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which of these allows interior mutability?

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

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which type of closure takes ownership of captured variables?

  • (A) |x| x + 1
  • (B) move |x| x + 1
  • (C) &|x| x + 1
  • (D) *|x| x + 1

S

Shyam Dubey • 3.70K Points
Extraordinary

Q. Which macro is commonly used for unit testing?

  • (A) unit_test!
  • (B) check!
  • (C) test!
  • (D) #[test]

R

Ravina • 3.96K Points
Extraordinary

Q. What is the purpose of the `dyn` keyword in Rust?

  • (A) Defines a dynamic variable
  • (B) Specifies a trait object
  • (C) Creates a macro
  • (D) Marks a function as dynamic

R

Ravina • 3.96K Points
Extraordinary

Q. Which trait is required to use the `==` operator?

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

R

Ravina • 3.96K Points
Extraordinary

Q. Which macro is used to include the contents of a file as a string?

  • (A) read_file!
  • (B) include_str!
  • (C) include!
  • (D) read_str!

R

Ravina • 3.96K Points
Extraordinary

Q. Which type is used to represent a slice of data?

  • (A) &str
  • (B) &[T]
  • (C) &Vec<T>
  • (D) &Box<T>