From the Rust guide:
To dereference (get the value being referred to rather than the reference itself)
y
, we use the asterisk (*
)
So I did it:
fn main() {
let x = 1;
let ptr_y = &x;
println!("x: {}, ptr_y: {}", x, *ptr_y);
}
This gives me the same results (x=1; y=1) even without an explicit dereference:
fn main() {
let x = 1;
let ptr_y = &x;
println!("x: {}, ptr_y: {}", x, ptr_y);
}
Why? Shouldn't ptr_y
print the memory address and *ptr_y
print 1? Is there some kind of auto-dereference or did I miss something?