Complete the code to declare an array of 5 integers in Rust.
let numbers: [i32; 5] = [1];
Arrays in Rust use square brackets to hold elements. So [1, 2, 3, 4, 5] is the correct syntax.
Complete the code to access the third element of the array named numbers.
let third = numbers[1];Arrays in Rust are accessed using square brackets with zero-based indexing. So numbers[2] gets the third element.
Fix the error in the code to create an array of 4 zeros.
let zeros = [0; [1]];
The syntax [value; count] creates an array with count copies of value. To create 4 zeros, use [0; 4].
Fill both blanks to create an array of 3 strings and access the first element.
let fruits: [&str; [1]] = ["apple", "banana", "cherry"]; let first = fruits[2];
The array has 3 elements, so the size is 3. To access the first element, use square brackets with index 0: fruits[0].
Fill both blanks to create a function that returns the length of an array of integers.
fn array_length(arr: &[i32; [1]]) -> usize { arr[2]len() }
len().len().The function takes a reference to an array of size 5. To call the len() method, use dot notation arr.len(). The function returns the length directly, so no extra symbol is needed after len().
