I'm learning about ownership and borrowing.
The difference between borrow1
and borrow2
is the usage of &
while printing in borrow2
:
fn borrow1(v: &Vec<i32>) {
println!("{}", &v[10] + &v[12]);
}
fn borrow2(v: &Vec<i32>) {
println!("{}", v[10] + v[12]);
}
fn main() {
let mut v = Vec::new();
for i in 1..1000 {
v.push(i);
}
borrow1(&v);
println!("still own v {} , {}", v[0], v[1]);
borrow2(&v);
println!("still own v {} , {}", v[0], v[1]);
}
Why do they give the same output, even though borrow1
doesn't have &
?