W3Reference.com
Toggle Menu
Home
Online Rust Compiler
Tutorials
Python Tutorial
Java Tutorial
Rust Tutorial
TypeScript Tutorial
ReactJS Tutorial
HTML & CSS Basics
Docker Containers Guide
Kubernetes Tutorial
Software Design Patterns
Blog
All Posts
Rust Programming Basics
Check your grasp of Rust syntax,ownership,and borrowing concepts.
1. What keyword is used to declare a mutable variable in Rust?
let
mut
var
mutable
2. Which of the following is NOT a basic numeric type in Rust?
i32
f64
str
u8
3. What is the result of the expression `5 + 3 * 2` in Rust?
16
11
10
13
4. Which of the following allows a function to return a value without using the `return` keyword?
Using the `return` keyword
Adding `->` to the function signature
Ending the line with a semicolon
Omitting the semicolon on the final expression
5. What does the `Option<T>` enum represent?
A value that may be null
A value that is always present
A mutable reference
A compile-time error
6. Which of the following is the correct way to create a string literal in Rust?
String::new()
"hello"
String::from("hello")
&str::new()
7. What is the default visibility of items in a Rust module?
Public
Private
Protected
Internal
8. Which trait allows a type to be printed with `println!("{}", x)`?
Debug
Display
Print
ToString
9. Which of the following are valid ownership rules in Rust?
Each value has a single owner
Values can be borrowed multiple times immutably
A mutable borrow can coexist with an immutable borrow
When the owner goes out of scope, the value is dropped
10. Which of these are primitive types in Rust?
i8
String
bool
Vec<T>
char
11. Which statements about Rust's error handling are true?
Rust uses `Result<T, E>` for recoverable errors
`panic!` is used for unrecoverable errors
The `try!` macro is still the preferred way to handle `Result`
The `?` operator can propagate errors
12. Which of the following are valid loop constructs in Rust?
for
while
loop
do-while
13. What are valid ways to handle a `Result<T, E>` in Rust?
Using a `match` expression
Using `if let`
Calling `unwrap()`
Calling `expect()`
14. Rust is a garbage-collected language.
True
False
15. The `&mut T` type represents a mutable reference.
True
False
16. In Rust, variables are mutable by default.
True
False
17. The `enum` keyword is used to define enumeration types in Rust.
True
False
18. What keyword is used to import items from another module? (lowercase)
19. What is the name of Rust's package manager and build tool? (lowercase)
20. What keyword is used to declare a function in Rust? (lowercase)
Reset
Answered 0 of 0 — 0 correct