美文网首页
Rust 常量、变量与可变性

Rust 常量、变量与可变性

作者: 村南一枝花 | 来源:发表于2019-04-01 09:56 被阅读0次

    常量是用const来定义

    const HELLO_WORLD = "hello world"
    

    变量是用let来定义

    let man = "mac"
    

    在变量中又分为不可变变量跟可变变量,区别如下

    let man = "ricky"
    let mut man = "ricky"
    

    隐藏 -----修改不可变变量的方式

    fn main() {
        let x = 5;
        let x = x + 1;
        let x = x * 2;
        println!("The value of x is: {}", x);
    }
    

    相关文章

      网友评论

          本文标题:Rust 常量、变量与可变性

          本文链接:https://www.haomeiwen.com/subject/kpjmbqtx.html