November 2017
Intermediate to advanced
264 pages
5h 45m
English
The variable n in the binding let n = 42i32; is stored on the stack. Values on the stack or on the heap can be accessed by pointers. A pointer is a variable that contains the memory address of some value. To access the value it points to, dereference the pointer with *. This happens automatically in simple cases like in println! macro or when a pointer is given as a parameter to a method. For example in the following code m is a pointer containing the address of n:
// see code in Chapter 7/code/references.rs:
let m = &n;
println!("The address of n is {:p}", m);
println!("The value of n is {}", *m);
println!("The value of n is {}", m);
The preceding code prints out the following output. The address of the variable n differs with ...
Read now
Unlock full access