Recall & Review
beginner Click to reveal answer
What is a Vector in Rust?
A Vector (
Vec<T>) is a growable, heap-allocated list type. It can change size during runtime and stores elements contiguously in memory.beginner Click to reveal answer
What is an Array in Rust?
An Array (
[T; N]) is a fixed-size collection of elements stored on the stack. Its size is known at compile time and cannot change.beginner Click to reveal answer
How do you declare a Vector and an Array in Rust?
Vector: <code>let v = Vec::new();</code> or <code>let v = vec![1, 2, 3];</code><br>Array: <code>let a = [1, 2, 3];</code>beginner Click to reveal answer
Can you change the size of a Vector or an Array after creation?
You can change the size of a Vector by adding or removing elements.
You cannot change the size of an Array after it is created; its size is fixed.
You cannot change the size of an Array after it is created; its size is fixed.
intermediate Click to reveal answer
Where are Vectors and Arrays stored in memory in Rust?
Arrays are stored on the stack because their size is fixed.
Vectors store their elements on the heap, but the Vector variable itself is on the stack.
Vectors store their elements on the heap, but the Vector variable itself is on the stack.
Which Rust type allows you to change the number of elements after creation?
✗ Incorrect
Vectors can grow or shrink during runtime, while arrays have a fixed size.
What is the size characteristic of a Rust array?
✗ Incorrect
Arrays have a fixed size that must be known when the program is compiled.
Where are the elements of a Rust Vector stored?
✗ Incorrect
Vectors store their elements on the heap to allow dynamic resizing.
Which Rust type requires its size to be known at compile time?
✗ Incorrect
Arrays must have a fixed size known at compile time.
How do you create a Vector with initial elements 1, 2, and 3 in Rust?
✗ Incorrect
The macro
vec![...] creates a Vector with the given elements.Explain the main differences between a Vector and an Array in Rust.
Think about size flexibility and memory location.
You got /4 concepts.
Describe a situation where you would prefer using an Array over a Vector in Rust.
Consider memory and performance constraints.
You got /3 concepts.
