programming beginner 10 sample questions

Rust MCQ Practice Test

A systems programming language focused on safety, speed, and concurrency.

Q1. Which Rust keyword is used to define a mutable reference to a value?

Explanation: In Rust, the 'mut' keyword is used to define a mutable reference to a value, allowing it to be modified.

Q2. In Rust, what is the purpose of the `std::mem::size_of` function?

Explanation: The `std::mem::size_of` function returns the size of a type in bytes as a `usize` value. This can be used to determine the size of a type at compile-time.

Q3. In Rust, what is the purpose of the `std::mem::drop` function?

Explanation: The `std::mem::drop` function is used to manually drop a value, which can be useful in certain situations where the value needs to be dropped immediately, such as when working with values that have a large memory footprint or when dealing with values that are not properly cleaned up by the Rust compiler.

Q4. What is the purpose of the 'match' keyword in Rust?

Explanation: The 'match' keyword in Rust is used to handle different cases in a function, similar to switch statements in other languages.

Q5. What is the purpose of the `std::sync::mpsc` module in Rust?

Explanation: The `std::sync::mpsc` module in Rust provides a thread-safe way for threads to communicate with each other, allowing for concurrent access to data through a message passing interface. This is achieved through the use of channels, which enable threads to send and receive messages in a safe and efficient manner.

Q6. What is the purpose of the `std::mem::drop` function in Rust?

Explanation: The `std::mem::drop` function is used to manually drop a value and reclaim its memory, which can be useful in certain situations such as when working with smart pointers or when trying to optimize memory usage.

Q7. In Rust, what does calling std::mem::drop(x) do?

Explanation: drop(x) gives up ownership of x immediately so its destructor runs — used to release resources such as locks early.

Q8. What is the purpose of the `\s` pattern in Rust regular expressions?

Explanation: In Rust regular expressions, the `\s` pattern is used to match any whitespace character, including spaces, tabs, and newlines.

Q9. In Rust, what is the purpose of the 'async' keyword when used with a function?

Explanation: The 'async' keyword in Rust is used to mark a function as asynchronous, allowing it to return a value that can be awaited by another task. This enables the function to yield control back to the caller, allowing other tasks to run in the meantime.

Q10. What is the purpose of the \`match\` statement in Rust?

Explanation: The \`match\` statement in Rust is used to handle different cases of a value, such as different variants of an enum or different values of a primitive type. It allows you to specify a value to match against and a set of possible values, and execute different code blocks based on the match.

That was just a sample. Sign up to unlock the full question bank with timed tests and certificates.

Sign Up Free
Rust MCQ Practice Test | Mind Hustle