Recall & Review
beginner Click to reveal answer
What is an array in Rust?
An array in Rust is a fixed-size collection of elements of the same type stored in contiguous memory. The size is known at compile time.
beginner Click to reveal answer
How do you declare an array of 5 integers initialized to zero in Rust?
You can declare it as: <code>let arr: [i32; 5] = [0; 5];</code> This creates an array of 5 integers, all set to 0.beginner Click to reveal answer
What does the syntax
[value; size] mean in Rust array initialization?It means create an array of length
size where each element is initialized to value.beginner Click to reveal answer
Can you change the size of an array after declaration in Rust?
No, arrays in Rust have a fixed size known at compile time and cannot be resized. For dynamic sizes, use vectors.
beginner Click to reveal answer
How to declare and initialize an array with different values in Rust?
You can declare it like: <code>let arr = [1, 2, 3, 4, 5];</code> The compiler infers the type and size from the values.What is the correct way to declare an array of 3 floats initialized to 1.0 in Rust?
✗ Incorrect
Option A correctly declares an array of 3 floats all initialized to 1.0. The syntax [value; size] is used for initialization.
What happens if you try to change the size of an array after declaration in Rust?
✗ Incorrect
Rust arrays have fixed size known at compile time. Changing size after declaration causes a compiler error.
Which of the following declares an array with elements 10, 20, 30 in Rust?
✗ Incorrect
Option B correctly declares an array with three elements 10, 20, 30. Option A is a tuple, not an array.
What is the type of
let arr = [5; 4]; in Rust?✗ Incorrect
The array has 4 elements each initialized to 5, so type is [i32; 4].
How do you declare an empty array in Rust?
✗ Incorrect
Option C declares an array of size 0. Rust allows zero-length arrays with explicit size.
Explain how to declare and initialize an array in Rust with the same value repeated.
Think about how to create multiple copies of the same value.
You got /3 concepts.
Describe the limitations of arrays in Rust compared to vectors.
Consider what happens if you want to add or remove elements.
You got /4 concepts.
