Reputation: 1245
fn main() {
println!("{:p}", &"aravindh");
println!("{:p}", &"test");
address_of(&"aravindh");
address_of(&"test");
}
fn address_of<A>(a:&A){
println!("{:p}", &a);
}
The output is:
0x10da08260
0x10da08278
0x7fff52231990
0x7fff52231990
While the address of first two strings are different, why are they same when printed via the address_of
function?
Upvotes: 2
Views: 45
Reputation: 58975
Because you're printing the address of the parameter a
, not the address of the thing it points to.
fn address_of<A>(a: &A){
println!("{:p}", a);
}
Upvotes: 4