Rust MCQs with answers Page - 33

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 'cargo' tool in Rust?

  • (A) Memory management
  • (B) Code formatting
  • (C) Package management and building
  • (D) Debugging

A

Admin • 831.35K Points
Coach

Q. Which of the following is a valid way to print to the console in Rust?

  • (A) echo("Hello")
  • (B) print("Hello")
  • (C) println!("Hello")
  • (D) console.log("Hello")

A

Admin • 831.35K Points
Coach

Q. What is the result of the following code?

Code:
fn main() {
    let s = String::from("hello");
    let t = s;
    println!("{}", s);
}
  • (A) hello
  • (B) Compilation error
  • (C) Undefined behavior
  • (D) Nothing

A

Admin • 831.35K Points
Coach

Q. What is the purpose of the 'Result' type in Rust?

  • (A) To store strings
  • (B) To handle errors
  • (C) To define structs
  • (D) To manage memory

A

Admin • 831.35K Points
Coach

Q. Which of the following is a valid way to define a struct in Rust?

  • (A) struct MyStruct { name: String }
  • (B) class MyStruct { name: String }
  • (C) type MyStruct = { name: String }
  • (D) object MyStruct { name: String }

A

Admin • 831.35K Points
Coach

Q. What is the output of this code?

Code:
fn main() {
    let x = vec![1, 2, 3];
    println!("{}", x[1]);
}
  • (A) 1
  • (B) 2
  • (C) 3
  • (D) Compilation error

A

Admin • 831.35K Points
Coach

Q. Which keyword is used to implement traits in Rust?

  • (A) trait
  • (B) impl
  • (C) interface
  • (D) define

A

Admin • 831.35K Points
Coach

Q. What does the 'unwrap()' method do on a Result type?

  • (A) Returns the error
  • (B) Returns the value or panics
  • (C) Ignores the value
  • (D) Converts to Option

A

Admin • 831.35K Points
Coach

Q. Which of the following is a macro in Rust?

  • (A) print
  • (B) println!
  • (C) format
  • (D) debug

A

Admin • 831.35K Points
Coach

Q. Which of the following types is used for optional values?

  • (A) Result
  • (B) Option
  • (C) Maybe
  • (D) Choice

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