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

Creating an array with the same value

fn main() {
    let counter = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
    println!("{} {:?}", counter.len(), counter);

    let counter = [0; 10];
    println!("{} {:?}", counter.len(), counter);

    let answer = [42; 4];
    println!("{} {:?}", answer.len(), answer);
}
10 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
10 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
4 [42, 42, 42, 42]