Search⌘ K

Multiple Variables and Shadowing

Explore how to work with multiple variables in Rust and understand the concept of shadowing, where new variables can reuse names by creating distinct bindings. This lesson helps you perform calculations by breaking them into parts and managing variable scope in your Rust programs.

We'll cover the following...

We’re not limited to just one variable. It’s fine to define as many as we’d like:

Rust 1.40.0
fn main() {
let x = 5;
let y = 10;
let name = "Michael";
println!("My name is {}, and the answer is {}", name, x + y);
}

We can also use this technique to break up ...