Variable shadowing
๐ Scenario: Imagine you are organizing a small event and need to keep track of the number of guests. Sometimes, you update the count temporarily for calculations without changing the original number.
๐ฏ Goal: You will create a variable to hold the initial guest count, then shadow it with a new value to show how variable shadowing works in Rust. Finally, you will print the final guest count.
๐ What You'll Learn
Create a variable called
guest_count with the value 50.Shadow the variable
guest_count by creating a new variable with the same name and assign it the value guest_count + 10.Print the value of
guest_count.๐ก Why This Matters
๐ Real World
Variable shadowing helps when you want to reuse a variable name for updated values without changing the original variable's mutability.
๐ผ Career
Understanding shadowing is important for writing clear and safe Rust code, which is valuable in systems programming and software development jobs.
Progress0 / 4 steps