arrays, vectors, slices Flashcards

know everything

1
Q

what is the syntax for creating an array

A

let arr: [u32; 3] = [1,2,3]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

is there special syntax for creating arrays of a single value?

A

let arr = [“blaster”; 12 ] // 12 different blasters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the syntax for accessing an array element

A

square brackets. inside the brackets is usize

arr[4]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Rust provides methods for arrays or methods for slices

A

Method for slices

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

will rust convert a reference to an array into a slice?

A

yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is the method to sort an array?

A

array.sort()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is the syntax for a function that takes an array as a parameter?

A

fn name( arr : &mut [u32, 4] ) {

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what is the syntax for a function that takes a slice as a parameter?

A

fn name( slice : &mut [u32]){

How well did you know this?
1
Not at all
2
3
4
5
Perfectly