Exerpad
🔥 0
0 XP
Exercise 4 · Chapter: Ownership & BorrowingRequired+50 XP

Mutable Borrow

Write a function called add_exclaim that takes a mutable borrow of a String and appends "!" to it. Call it twice on the same string, then print the result.

Expected output:

Wow!!

Hints:

  • The function signature: fn add_exclaim(text: &mut String)
  • Use text.push_str("!") to append
  • The variable must be declared with let mut
  • Pass it with &mut my_string
rust
fn main() {
}
Output
Run your code to see the output here.