Rust 01

ukyo--BlackJesus發表於2024-04-15
//https://kaisery.github.io/trpl-zh-cn/ch03-02-data-types.html
fn main() {
    println!("Hello, world!");
    //標量(scalar)型別代表一個單獨的值。Rust 有四種基本的標量型別:整型、浮點型、布林型別和字元型別。
    // 你可能在其他語言中見過它們。讓我們深入瞭解它們在 Rust 中是如何工作的。

    //數值型別 整型 浮點
    let a = 2;

    println!("a :{a}");

    let b = 2.0;
    let c:f32 = 3.0;

    let sum = 5 + 10;
    let diff = 95.5-4.3;

    let product = 4*30;

    let quotient = 56.7/32.2;

    let truncated = -5/3;

    let remainder = 43%5;

    println!("remainder :{remainder}");

    //布林型別
    let t = true;
    let f:bool = false;

    println!("t:{t} f:{f}");

    //字元型別
    let str1 = 'z';
    let z_al :char = 'Z';
    let black_hat = '🎩';

    println!("str1:{str1} z_al:{z_al} black_hat:{black_hat}");


}

相關文章