General Rust II
1.
How does Rust handle integer overflow by default?
It wraps around to the minimum value
It panics at runtime
It ignores the overflow
It automatically promotes to a larger integer type
2.
How does Rust handle global variables?
By declaring them inside the `main` function
By using the `static` keyword
By using the `global` keyword
By relying on garbage collection
3.
In Rust, what is the purpose of the `break` keyword?
To terminate the program
To exit a loop prematurely
To declare a constant
To handle exceptions
4.
What is the purpose of the `const` keyword in Rust?
To create a new module
To define a structure
To declare a constant
To indicate a mutable variable
5.
What is the purpose of the `unsafe` keyword in Rust?
To handle exceptions
To define a constant
To indicate unsafe code that requires manual checks
To specify the visibility of a variable
6.
What is the purpose of the `as` keyword in Rust?
To cast between different types
To define a macro
To create a new module
To handle exceptions
7.
How is error handling typically done in Rust functions?
Using the `try` keyword
Returning a `Result` type
Using the `throw` keyword
Using global variables for errors
8.
What is the role of the `self` keyword in Rust?
To declare a constant
To represent the current instance of a type
To specify the visibility of a variable
To create a new module
9.
How does Rust support pattern matching with the `if let` syntax?
It performs bitwise AND operations
It defines a loop
It declares a constant
It checks if a variable matches a specific pattern
10.
What is the purpose of the `drop` trait in Rust?
To handle exceptions in Rust
To free resources when a value goes out of scope
To define a generic type
To implement garbage collection
11.
What is a closure in Rust?
A loop that repeats a specific number of times
A function that captures variables from its environment
A type of data structure
A mechanism for error handling
12.
What does the `match` keyword in Rust offer over `if-else` statements?
More expressive pattern matching
Faster execution speed
Simpler syntax
Dynamic typing
13.
How does Rust ensure thread safety?
By using locks and mutexes
Through ownership and borrowing rules
By relying on garbage collection
By implementing automatic parallelization
14.
What is the purpose of the `Cow` type in Rust?
To represent a collection of values
To handle ownership of a value
To manage the lifetime of a variable
To efficiently handle both owned and borrowed data
15.
How does Rust support parallelism?
By avoiding parallelism altogether
Through the use of threads and the `Rayon` library
By relying on garbage collection
Through reference counting
16.
What is the purpose of the `assert!` macro in Rust?
To define a new module
To create a custom attribute
To perform runtime assertions
To handle exceptions
17.
In Rust, what is the purpose of the `Drop` trait?
To specify a lifetime
To handle exceptions in Rust
To represent a numeric type
To define custom cleanup code when a value goes out of scope
18.
How does Rust enforce strict aliasing rules?
By relying on runtime checks
Through garbage collection
By using ownership and borrowing
By using the `unsafe` keyword
19.
What is the purpose of the `derive` attribute in Rust?
To define a macro
To generate code automatically
To specify the visibility of a variable
To handle exceptions
20.
How does Rust manage dynamic dispatch for trait objects?
Automatically without any keyword
Using the `dyn` keyword
By relying on the garbage collector
By declaring functions as `dynamic`