初級 › E0384: cannot assign twice to immutable variable の原因と直し方 › パターン3
E0384: cannot assign twice to immutable variable の原因と直し方
Rustの変数はデフォルトで不変(immutable)です。
1 fn main() { 2 let _______total = 100; ^ 3 total = 200; 4 println!("{}", total); 5 }
error[E0384]: cannot assign twice to immutable variable `total`
空欄を埋めて実行を通す
letの後にmutを付けるかどうかで、その変数が後から書き換え可能かどうかが決まります。
次の問題