I've tried the following code in the Rust playground thinking one of the options would either reveal the memory location where x
was stored, or at least throw an error:
fn main() {
let x = 2;
let y = &x;
println!("Value of x: {}", x);
println!("Value of x: {:?}", &x);
println!("Value of y: {:?}", y);
println!("Value of y: {}", *y);
}
Instead, I got this output:
Value of x: 2
Value of x: 2
Value of y: 2
Value of y: 2
Am I totally misunderstanding the way Rust refers to memory locations & the way it dereferences them? Or, is there something funny about the println! macro that I'm missing? Or, just something I'm not getting about the way it allows operations to take place on memory locations?