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

Pass mutable reference of integer to function

fn increment(x: &mut i32) {
    *x += 1;
}

fn main() {
    let mut a = 1;
    println!("{a}");
    increment(&mut a);
    println!("{a}");
}
1
2