rust变量与可变性

fn main() {
    //let x = 5;
    let mut x = 5;
    //通过const定义常量名称要大写,并且值不可更改
    const Y:i32=6;
    println!("Y is {}",Y);
    println!("The value of x is {}", x);
    x = 6;
    println!("The value of x is {}", x);

    //如果要覆盖上一个变量 需要使用let
    //如果不是let而改变了x的类型会出错
    //x = 1.23;
    let x = "hello";
    println!("x type changed to string ,{}",x);
    let x = x.len();
    println!("x len is {}",x)
}

猜你喜欢

转载自www.cnblogs.com/c-x-a/p/11964846.html