Skip to content
Justice Tech School

Arrays

Arrays have a fixed length known at compile time. Use len and index from 0.

Example
fn main() {
    let a = [1, 2, 3];
    let z = [0; 4];
    println!("{:?} {:?} {} {}", a, z, a.len(), a[1]);
}

Result

[1, 2, 3] [0, 0, 0, 0] 3 2

Exercise

Repeat a value.

[0; ]

Quiz Test

What does [0; 4] make?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.