rust学习笔记-2
变量:默认是不可修改的 let用于声明变量,修改变量会导致编译会报错 fn main() { let x = 5; println!("The value of x is: {x}"); x = 6; println!("The value of x is: {x}"); } 加mut声明x为可修改的: fn main() { let mut x = 5; println!("The value of x is: {x}"); x = 6; println!("The value of x is: {x}"); } 话说rust的编译报错的错误提示还是蛮好看的: % cargo build Compiling variables v0.1.0 error[E0384]: cannot assign twice to immutable variable `x` --> src/main.rs:4:5 | 2 | let x = 5; | - | | | first assignment to `x` | help: consider making this binding mutable: `mut x` 3 | println!...