simple example showcasing stack vs heap behavior

let w = 5;

let x = w; // two copies of value w now on the stack

let y = Box::new(w); // copy value w on the heap (y points to it from stack)

let z = y // ownership change. y goes out of scope and now z points to that value on the heap.

Reply to this note

Please Login to reply.

Discussion

No replies yet.