I have a variable without a value, but I can assign it without mut. I want to ask if, if the variable has no value, it can be assigned without mut.
sorry my English is bad
let a: u8;
a = 10;
println!("{}", a);
I have a variable without a value, but I can assign it without mut. I want to ask if, if the variable has no value, it can be assigned without mut.
sorry my English is bad
let a: u8;
a = 10;
println!("{}", a);
As a technicality, the first line is a variable declaration, defining the type and name. The declaration does not initialize the value inside of a
. You cannot access data from an uninitialized variable. Line 2 initializes it with the value 10, making it usable on line 3.
If you want more information on this, I recommend you read Chapter 5 of the Rustonomicon, which covers this topic in more detail.
thank you I understand and read the documentation
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.