Rust 常量、变量与可变性

2019-04-01  本文已影响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);
}
上一篇下一篇

猜你喜欢

热点阅读