Rust: Funções

From Wiki
Revision as of 01:33, 12 May 2020 by Ebasso (talk | contribs) (Criou a página com "Usando Funções em Rust <nowiki> fn outra_funcao(x: i32, y: i32) { println!("x = {}", x); println!("y = {}", y); } fn cinco() -> i32 { 5 } fn soma_um(x: i3...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Usando Funções em Rust


fn outra_funcao(x: i32, y: i32) {
    println!("x = {}", x);
    println!("y = {}", y);
}

fn cinco() -> i32 {
    5
}

fn soma_um(x: i32) -> i32 {
    x + 1
}

fn main() {
    println!("");

    //Declaracoes e Expressoes
    outra_funcao(5, 6);
    println!("");

    // Funções com valor de retorno
    let cin = cinco();
    println!("cinco = {}", cin);
    println!("");

    let su = soma_um(5);
    println!("su = soma_um(5) = {}", su);
    println!("");

    let x = 5;
    let y = {
        let x = 3;
        x + 1
    };
    println!("x = {}", x);
    println!("y = {}", y);
    println!("let z = (let y = 6); ---> Daria erro");

}

 

Ver também