#![allow(unused)] fnmain() { // 变量默认是不可变的,如要声明可变变量,应使用mut关键字 // let x = 5; letmut x = 5; println!("The value of x is {}", x); // 5 x = 6; println!("The value of x is {}", x); // 6
// 遮蔽(shadow),可以通过使用相同的变量名并重复使用 let 关键字来遮蔽之前的变量 letx = 5; letx = x + 1; { letx = x * 2; println!("The value of x in the inner scope is: {}", x); // 12 } println!("The value of x is: {}", x); // 6