fn main()
{
let mut x = 10;
let y = &mut x;
*y += 10; // Why do we need the dereference * symbol?
println!("{}", y);
}
I don't get why we need this deference * in *y += 10; since we don't need this symbol when we are printing y onto the console so why do we need it when we need to change the value?
Usually yes. There are cases where Rust is more clever about this. Types can implement Deref trait to customize what gets dereferenced. Also the combination of &* is guaranteed not to do the silly thing of referencing a temporary dereference, but to be optimized into address/type manipulation that doesn't read memory behind the reference.