How to use the formal parameters of Go
This article mainly explains "how to use the formal parameters of Go". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use the formal parameters of Go".
Formal parameter
Formal arguments are used as local variables of the function. Examples are as follows:
Example
Package main
Import "fmt"
/ * declare global variables * /
Var an int = 20
Func main () {
/ * declare a local variable in the main function * /
Var an int = 10
Var b int = 20
Var c int = 0
Fmt.Printf (a =% d\ n in the "main () function, a)
C = sum (a, b)
Fmt.Printf ("main () function c =% d\ n", c)
}
/ * function definition-add two numbers * /
Func sum (a, b int) int {
Fmt.Printf (a =% d\ n in the "sum () function, a)
Fmt.Printf ("sum () function b =% d\ n", b)
Return a + b
}
The output of the above example is as follows:
Main () function a = 10sum () function a = 10sum () function b = 20main () function c = 30 thank you for reading, the above is "how to use the formal parameters of Go" content, after the study of this article, I believe that you have a deeper understanding of how to use the formal parameters of Go, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!