Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Rust array of numbers, length of array

  • len

  • Create array

  • Get the number of elements, the length of the array using len.

  • Access elements in the array using square bracket indexing.

fn main() {
    let numbers: [i8; 3] = [10, 11, 12];

    println!("{:?}", numbers);
    println!("{}", numbers.len());
    println!("{}", numbers[0]);
}
[10, 11, 12]
3
10