&String storage whose memory address?

It's String's memory address on the stack.
Internally, String contains another pointer to the str on the heap.

Also you can paste code to this forum using triple backticks ``` like this:

fn main() {
    let x = String::from("hello");
    let p = &x;
    let q = p.as_str();
    println!("Address of the String on the stack: {p:p}");
    println!("Address of the str on the heap {q:p}");
}
2 Likes