Why reference a type? e.g. let third: &i32 = &v[2]

I'm going thru "the book" and in listing 8-4:

fn main() {
    let v: Vec<i32> = vec![1, 2, 3, 4, 5];
    let third: &i32 = &v[2];
    println!("v={:#?}", third);
}

the third line references the "i32" (let third: &i32 = ...). Why reference a type? I understand why you'd want to reference a variable, but why a type?

Thanks!

It's not referencing the type, it means the type of the variable is a reference to an i32.

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.