Commit 38932fa9 authored by Chris's avatar Chris
Browse files

[variables] added some content to main & explanations

parent 611f73a5
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "variables"
version = "0.1.0"
+6 −0
Original line number Diff line number Diff line
[package]
name = "variables"
version = "0.1.0"
edition = "2024"

[dependencies]
+27 −0
Original line number Diff line number Diff line
fn main() {
//    let mut x = 5;
//    println!("The value of x is {x}");
//    x = 6;
//    println!("The value of x is {x}");

    let x1 = 5;
    let x1 = x1 + 1;
    {
        let x1 = x1 * 2;
        println!("The value of x1 in the inner scope is: {x1}");
    }

    println!("The value of x1 is: {x1}");

    let mut x: u32 = 1;
    {
        let mut x = x;
        x += 2;
    }
    println!("{x}"); // this outputs 1 because the shadowed value == 3 stays in scope of the brackets


    // let mut y: u32 = 1;
    // y = "Hello world"; // doesn't compile: you're trying to shadow a mut variable with a different data type, which is not allowed!
    // println!("{y}");
}