Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Swap Values

Write a function called swap that takes mutable borrows of two i32 values and swaps them. Print before and after to show the swap worked.

Expected output:

text
Before: a=10, b=20
After: a=20, b=10

Hints:

  • Function signature: fn swap(a: &mut i32, b: &mut i32)
  • Use a temporary variable: let temp = *a;
  • Use *a and *b to read/write the values behind the references
rust
fn main() {
}