arrays, vectors, slices Flashcards
know everything
1
Q
what is the syntax for creating an array
A
let arr: [u32; 3] = [1,2,3]
2
Q
is there special syntax for creating arrays of a single value?
A
let arr = [“blaster”; 12 ] // 12 different blasters
3
Q
What is the syntax for accessing an array element
A
square brackets. inside the brackets is usize
arr[4]
4
Q
Rust provides methods for arrays or methods for slices
A
Method for slices
5
Q
will rust convert a reference to an array into a slice?
A
yes
6
Q
what is the method to sort an array?
A
array.sort()
7
Q
what is the syntax for a function that takes an array as a parameter?
A
fn name( arr : &mut [u32, 4] ) {
8
Q
what is the syntax for a function that takes a slice as a parameter?
A
fn name( slice : &mut [u32]){