Search⌘ K

Solution Review: Defining Variables

Understand how to define variables in Rust, including mutable and immutable types, and how to assign and update their values. Explore basic variable usage to build a foundation for working with data types and advanced Rust concepts.

We'll cover the following...

Solution:

Rust 1.40.0
fn test() {
// declare a mutable variable `x`
let mut x = 1000;
// declare a variable `y`
let y="Programming";
// print output of `x`
println!("x:{}", x);
// print output of `y`
println!("y:{}", y);
// update x
x = 1100;
// print output of `x`
println!("x:{}", x);
// print output of `y`
println!("y:{}", y);
}

Explanation

  • On line 3, a mutable variable x is defined and assigned the
...