Skip to content

Instantly share code, notes, and snippets.

@RGGH
Created December 1, 2022 16:00
Show Gist options
  • Save RGGH/4a4335b92048ad39ce2fff872084e6e9 to your computer and use it in GitHub Desktop.
Save RGGH/4a4335b92048ad39ce2fff872084e6e9 to your computer and use it in GitHub Desktop.
Update Array from a Function - Rust
fn main() {
let mut arr: [i32; 4] = [1, 2, 3, 4];
change_value(&mut arr);
for x in arr {
print!("{} ", x);
}
}
fn change_value(arr: &mut [i32]) {
arr[1] = 10;
arr[2] = 20;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment