General Rust I
1.
What does the `mut` keyword in Rust indicate?
It specifies a module
It denotes a constant value
It indicates a mutable reference
It represents an external crate
2.
How does Rust manage memory safety?
Manual memory management
Garbage collection
Automatic reference counting
Ownership system with borrowing rules
3.
Which of the following is a trait in Rust?
Class
Interface
Trait
Abstract class
4.
What is the purpose of the `match` keyword in Rust?
It declares a function
It defines a loop
It performs pattern matching
It specifies a generic type
5.
In Rust, what is the purpose of the `struct` keyword?
It defines a function
It declares a constant
It specifies a module
It defines a structure
6.
What is the ownership principle in Rust?
Ownership is determined by a central authority
Every value has a single owner and a single borrower
Ownership is shared among all references
Ownership is handled by garbage collection
7.
What does the `Vec` type represent in Rust?
An array
A tuple
A linked list
A vector
8.
How does Rust handle concurrency?
With global variables
With threads and the ownership system
With automatic parallelization
With reference counting
9.
What is the purpose of the `Option` type in Rust?
To represent a choice between multiple values
To declare optional function parameters
To handle optional values
To define a generic type
10.
What is borrowing in Rust?
A method to create immutable references
A way to permanently transfer ownership
A form of garbage collection
A mechanism to temporarily share ownership
11.
How are lifetimes used in Rust?
To handle memory leaks
To define the duration of a program
To specify the lifetime of a variable
To manage the scope of references
12.
What does the `unwrap` method do for `Result` in Rust?
Extracts the value if it's `Ok` or panics if it's `Err`
Handles errors gracefully
Returns a default value for `Err`
Converts `Result` into `Option`
13.
What is Rust's ownership model designed to prevent?
Multiple inheritance issues
Garbage collection overhead
Infinite loops
Data races and null pointer dereferences
14.
How does Rust achieve zero-cost abstractions?
Through runtime checks
Through interpreted code
Through extensive documentation
Through static analysis at compile time
15.
What is the purpose of the `enum` keyword in Rust?
To define a numeric type
To declare a constant
To define an enumeration
To represent a floating-point number
16.
Which keyword is used for error handling in Rust?
`panic`
`error`
`fail`
`Result`
17.
What does the `Cargo` tool in Rust provide?
Text editing capabilities
User interface design
Database management
Package management and build system
18.
How does Rust achieve fearless concurrency?
By using locks and mutexes
By avoiding concurrency altogether
By enforcing strict ownership rules
By relying on garbage collection
19.
What is the role of the `use` keyword in Rust?
To import modules and symbols
To declare a function
To define a structure
To specify a lifetime
20.
Which of the following is true about Rust's ownership system?
It allows multiple mutable references to the same data
It prevents data races by enforcing ownership rules
It relies on garbage collection for memory management
It permits null pointer dereferences
21.
What does the `&` symbol represent in Rust?
Indicates a mutable variable
Specifies a macro
Denotes a reference
Represents bitwise AND