Can global and local variable names be the same in Go language?
This article "Go language global variables and local variable names can be the same?" most people do not understand, so the editor summarized the following content, detailed, clear steps, with a certain reference value, I hope you can get something after reading this article, let's take a look at this "Go language global variables and local variable names can be the same" article it.
Global and local variable names can be the same in Go language programs, but local variables within functions are preferred. Examples are as follows:
Package main
Import "fmt"
/ * declare global variables * /
Var g int = 20
Func main () {
/ * declare local variables * /
Var g int = 10
Fmt.Printf ("result: G =% d\ n", g)
}
The output of the above example is as follows:
Results: G = 10 or more is about the article "can global variables and local variables have the same name in Go language?". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.