- 下面这段程序,第一个x输出为12,第二个x输出为6(可以理解大括号内的let为重新定义的变量)
fn main() {
let x = 5;
let x = x + 1;
{
let x = x * 2;
println!("The value of x in the inner scope is: {}", x);
}
println!("The value of x is: {}", x);
}
- 下面这段程序,第一个x输出为12,第二个x输出为12
fn main() {
let mut x = 5;
x = x + 1;
{
x = x * 2;
println!("The value of x in the inner scope is: {}", x);
}
println!("The value of x is: {}", x);
}