You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`func` is the key word of function `functionName` is the identifier or name of the function, the following `parameter1, parameter2, ...` is the parameter list of the function,`returnType`is optional, which is the returned type of the function. Function body is a series of sentences surrounded by `{}`. Here’s a example below:
19
+
`func` is the key word of function `functionName` is the identifier or name of the function, the following `parameter1, parameter2, ...` is the parameter list of the function,`returnType`is optional, which is the returned type of the function. Function body is a series of statements surrounded by `{}`. Here’s a example below:
20
20
21
21
```mcfpp
22
22
func add(int a, int b) -> int{
@@ -30,7 +30,7 @@ The name of the function is `add`, it have two integer-type parameters `a` and `
30
30
31
31
`return` is same as the `return` command in Minecraft, both used to return the returned value of the function. It’s grammar is `return expression;`, `expression` is an expression, it’s value is the returned value of the function.
32
32
33
-
If a function defined the type of the returned value, then each branch of it must have `return`sentence, so the function must would return a value. And the value that `return`sentence returned must have the same type as the type of return value of the function, or the subtype of the returned value’s type.
33
+
If a function defined the type of the returned value, then each branch of it must have `return`statement, so the function must would return a value. And the value that `return`statement returned must have the same type as the type of return value of the function, or the subtype of the returned value’s type.
34
34
35
35
If a function haven’t defined the return value’s type, then the default is `void`, which won’t return any value. Now, `return` statement is still available, but its grammar becomes `return;`, without any expression. Its function is stop the function immediately.
36
36
@@ -47,7 +47,7 @@ func test(){
47
47
48
48
In this example, `test` function called `add` function, and sent two parameters `1` and `2`. `add` function returns `3`, so the `test` function will print `3`.
49
49
50
-
## The parameter passing of function
50
+
## The argument of function
51
51
52
52
In the function, the change to the parameter won’t affect the variables out of the function. For example:
53
53
@@ -63,4 +63,4 @@ void main(){
63
63
}
64
64
```
65
65
66
-
In this case, `test` function modified the passing parameter `a`, but the `a` in `main` function haven’t been affected.
66
+
In this case, `test` function modified the passed in parameter `a`, but the `a` in `main` function haven’t been affected.
0 commit comments