Pass by Reference

fn main(){
  let mut by\_ref = 3;      // => 3
  power\_of\_three(&mut by_ref);
  println!("{by\_ref}");  // => 9
}
fn power\_of\_three(by_ref: &mut i32){
  // de-referencing is important
  *by_ref = *by_ref * *by_ref;
  println!("{by\_ref}");  // => 9
}
Comments