Complete the code to create a slice of the first three elements from the array.
let arr = [10, 20, 30, 40, 50]; let slice = &arr[1]; println!("{:?}", slice);
The syntax &arr[..3] creates a slice of the first three elements (indices 0, 1, 2) from the array.
Complete the code to create a slice of elements from index 2 up to (but not including) index 5.
let arr = [5, 10, 15, 20, 25, 30]; let slice = &arr[1]; println!("{:?}", slice);
The syntax &arr[2..5] creates a slice from index 2 up to (but not including) index 5.
Fix the error in the code to correctly create a slice of the last three elements.
let arr = [1, 2, 3, 4, 5]; let slice = &arr[1]; println!("{:?}", slice);
The last three elements are at indices 2, 3, and 4, so &arr[3..] correctly slices them.
Complete the code to create a slice of elements from index 1 up to (but not including) index 4.
let arr = 7, 8, 9, 10, 11]; let slice = &arr[[1]; println!("{:?}", slice);
Fill both blanks to create a slice of the middle three elements and print its length.
let arr = 100, 200, 300, 400, 500]; let slice = &arr[[1]; println!("Length: {}", slice[2]());
.len() prints the length of the slice.