Rust MCQs with answers Page - 3

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

A

Admin • 831.35K Points
Coach

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

  • (A) Marks a function as mutable
  • (B) Marks a variable as mutable
  • (C) Changes data type
  • (D) Imports a module

A

Admin • 831.35K Points
Coach

Q. Which data type in Rust can store a dynamically sized string?

  • (A) &str
  • (B) String
  • (C) char
  • (D) str

A

Admin • 831.35K Points
Coach

Q. Which Rust feature prevents data races at compile time?

  • (A) Garbage collection
  • (B) Ownership model
  • (C) Null pointers
  • (D) Thread pools

A

Admin • 831.35K Points
Coach

Q. Which of the following is a valid function declaration in Rust?

  • (A) function greet() {}
  • (B) fn greet() {}
  • (C) def greet() {}
  • (D) func greet() {}

A

Admin • 831.35K Points
Coach

Q. What will `vec![1, 2, 3]` create?

  • (A) A tuple
  • (B) A set
  • (C) A vector
  • (D) A string

A

Admin • 831.35K Points
Coach

Q. What is the default behavior of variables in Rust?

  • (A) Mutable
  • (B) Constant
  • (C) Global
  • (D) Immutable

A

Admin • 831.35K Points
Coach

Q. Which collection type allows key-value pairs in Rust?

  • (A) Vec
  • (B) Tuple
  • (C) HashMap
  • (D) Array

A

Admin • 831.35K Points
Coach

Q. What is the result type of a function that doesn't return anything?

  • (A) None
  • (B) null
  • (C) ()
  • (D) void

A

Admin • 831.35K Points
Coach

Q. What is the purpose of `impl` block in Rust?

  • (A) To import external packages
  • (B) To define function interfaces
  • (C) To implement methods for a struct or trait
  • (D) To execute main function

A

Admin • 831.35K Points
Coach

Q. Which of the following is NOT a valid Rust macro?

  • (A) println!
  • (B) format!
  • (C) vec!
  • (D) list!

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