1 | initial version |
In Rust, you can create mutable variables and change their values. If you have a memory location represented by a mutable variable, you can change its value using the assignment operator =
.
Here's an example of changing the value of a mutable variable representing a memory location:
fn main() {
let mut num = 10;
println!("Original Value: {}", num); // Output: Original Value: 10
num = 20;
println!("New Value: {}", num); // Output: New Value: 20
}
In this example, the variable num
is created with an initial value of 10
. Then, the value of num
is changed to 20
by using the assignment operator =
.
It's important to note that in Rust, you can't directly manipulate raw memory. All memory operations must go through a safe API provided by Rust's standard library or external libraries. This is done to prevent unsafe behavior and memory errors.