Function

Function#

Function Definition#

Functions are created using the fn keyword as follows.
There is no need to consider the order in which functions are defined, as long as they are defined somewhere within a scope.
Therefore, in the example code below, the hello() function is located after the main() function, and it compiles and runs correctly.

fn main() {
    hello();
}

fn hello() {
    println!("hello");
}

Parameter#

You can pass parameters when calling a function, as shown in the following example code.
The add function can take two parameters, a and b, both of type i64.
You must declare the type of each parameter, like i64, when receiving them in a function.
You can pass multiple parameters.