rust变量与可变性

时间:2019-12-01 10:08:38   收藏:0   阅读:54
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)
}

原文:https://www.cnblogs.com/c-x-a/p/11964846.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!