rust 函数的使用

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);

}

猜你喜欢

转载自www.cnblogs.com/c-x-a/p/11964884.html