Rust 编程视频教程对应讲解内容-类型

视频地址

头条地址:https://www.ixigua.com/i676544267458235648...
B站地址:https://www.bilibili.com/video/av78062009?...
网易云课堂地址:https://study.163.com/course/introduction....

讲解内容

use std::usize;
fn show(arr: [u32; 3]) {
    for i in &arr {
        println!("{}", i);
    }
}

fn main() {
    //bool
    let is_ok: bool = true;
    let is_error = false;
    println!("is_ok = {}", is_ok);
    println!("is_error = {}", is_error);

    //char 特别注意,rust char类型占32位,可以是一个汉字
    let he: char = '你';
    println!("he is {}", he);

    //数字类型: i8, i16, i32, i64, u8, u16, u32, u64, f32, f64
    let a: i8 = 1;
    let b: f32 = 0.0008;
    println!("a = {}", a);
    println!("b = {}", b);

    //自适应类型isize, usize
    println!("max = {}", usize::max_value());

    //数组
    //定义:[Type; size]
    let a: [u32; 3] = [1, 2, 3];
    //let b: [u32; 4] = [1, 2, 3, 4];
    println!("a[1] == {}", a[1]);
    show(a);
    //show(b);

    //元组
    //let tup: (i32, f32, u32) = (500, 0.6, 11);
    let tup = (500, 0.6, 11);
    println!("0 = {}", tup.0);
    println!("1 = {}", tup.1);
    println!("2 = {}", tup.2);

    let (x, y, z) = tup;
    println!("x = {}", x);
    println!("y = {}", y);
    println!("z = {}", z);

    println!("Hello, world!");
}
本作品采用《CC 协议》,转载必须注明作者和本文链接

令狐一冲

讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!