mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-07 03:09:19 +00:00
30 lines
846 B
Rust
30 lines
846 B
Rust
// pointers1.rs
|
|
// Where you pass a variable as parameters, you are not passing that variable
|
|
// instance itself, the compiler will make a copy of that variable for the use
|
|
// on that scope.
|
|
// For manage that you need to work with a pointer variable, because you are
|
|
// going to know exactly where the variable was allocated.
|
|
// The variables are passing on the parameters as its respective memories
|
|
// addresses, not the values itself.
|
|
// Make me compile! Execute `rustlings hint pointers1` for hints :)
|
|
|
|
// I AM NOT DONE
|
|
|
|
// TODO: Something is wrong on this function body
|
|
pub fn change_vals(a: &mut i32, b: &mut i32) {
|
|
let c: i32 = *a;
|
|
|
|
a = *b;
|
|
b = c;
|
|
}
|
|
|
|
fn main() {
|
|
let mut a: i32 = 5;
|
|
let mut b: i32 = 3;
|
|
|
|
println!("BEFORE {} e {}", a, b);
|
|
|
|
change_vals(&mut a, &mut b);
|
|
|
|
println!("AFTER {} e {}", a, b);
|
|
} |