...

/

What's In a Reference?

What's In a Reference?

We'll cover the following...

Every value in Rust lives somewhere in your computer’s memory. And every place in computer memory has an address. It’s possible to use println and the special {:p} syntax to display the address itself:

Press + to interact
fn main() {
let x: i32 = 5;
println!("x == {}, located at {:p}", x, &x);
}

On my computer, this prints x == 5, located at 0x7ffeeb9b68f4. A reference can be thought of as a pointer; it’s an address pointing at a value that lives somewhere else. That’s also why we use the letter p in the format string ...