xxxxxxxxxx
//Array declaration. Array sizes must be known at compile time
let my_array: [i32; 5] = [1, 2, 3, 4, 5];
//If the size of the array is not known at compile time. Use a slice or a vector
// This is how you access a element of a array, just type the index of the element between the square brackets
let x = my_array[0]
xxxxxxxxxx
//Array declaration. Array sizes must be known at compile time
let my_array: [i32; 5] = [1, 2, 3, 4, 5];
//If the size of the array is not known at compile time. Use a slice or a vector
xxxxxxxxxx
fn main() {
let a = [1, 2, 3, 4, 5];
let first = a[0];
let second = a[1];
}
xxxxxxxxxx
fn main() {
// this is how you init a array = [elements]
let array = [1, 2, 3, 4, 5];
println!("{:?}", array);
// this is how you define the type of the array [<type>; <size>] = [elements]
let array : [i32; 5] = [1, 2, 3, 4, 5];
println!("{:?}", array);
// this is how you init a array with a default :: = [<type and default value>, <size>]
let array = [1; 5];
println!("{:?}", array);
// this is same above array, but hand typed. [<type>; <size>] = [<type and default value>, <size>]
let array : [i32; 5] = [1; 5];
println!("{:?}", array);
}