Mutable to Immutable

We'll cover the following...

Does the following program compile?

Press + to interact
fn printme(x: &i32) {
println!("{}", x);
}
fn main() {
printme(&5);
}

It sure does! We only read from the immutable reference, x, and therefore everything is fine. How about this program?

Press + to interact
fn printme(x: &mut i32) {
println!("{}", x);
}
fn main() {
printme(&mut 5);
}

Yes, this is fine as well. We ...

Access this course and 1400+ top-rated courses and projects.