PR3-Rust-SS26/D-ownership/example-code/02-ownership/scope.rs

9 lines
245 B
Rust

fn main() {
// s is not valid here, since it's not yet declared
{
let s = "hello"; // s is valid from this point forward
// do stuff with s
println!("{s}");
} // s is no longer valid since the scope is over
}