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

Fix the Borrow

This code tries to modify a borrowed String, but the borrow isn't mutable! Fix it so the program prints:

Hello, World!

Hint: You need &mut instead of &, and the variable must be declared with mut.

rust
fn add_world(text: &String) {
text.push_str(", World!");
}

fn main() {
let greeting = String::from("Hello");
add_world(&greeting);
println!("{}", greeting);
}
Output
Run your code to see the output here.