首页 > 其他 > 详细

rust 函数的使用

时间:2019-12-01 09:52:01      阅读:61      评论:0      收藏:0      [点我收藏+]
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);

}

rust 函数的使用

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!