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

String Length

Write a function called print_length that borrows a String and prints its length. Call it from main, then print the string itself to show it's still valid.

Expected output:

Length: 11
Word: programming

Hints:

  • Use fn print_length(text: &String) to borrow
  • Use text.len() to get the length
  • The string "programming" has 11 characters
rust
fn main() {
}
Output
Run your code to see the output here.