rust 函数的使用

时间:2019-12-01 09:52:01   收藏:0   阅读:61
fn main() {
    println!("Hello, world!");
    another_function(2,3);
    let y ={
        let x =3;
        //表达式的结尾没有分号,如果在表达式的结尾加上分号,它就变成了语句,而语句不会返回值。
        x+1
    };
     println!(" the value in main of y is {}",y);
     let x = five();
     println!(" the value in main of x is {}",x);


}
// ->表示返回值后面加类型
//上面说了表达式没有分号,它还可以隐式的表示return 5
fn five()->i32 {
    5
}
//函数名小写中间加下划线
//大多数静态语言一样参数需要指定类型
fn another_function(x:i32,y:u32){
    println!(" the value of x is {}",x);
    println!(" the value of y is {}",y);

}

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

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