mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 03:06:41 +08:00
20 lines
236 B
Go
Executable File
20 lines
236 B
Go
Executable File
package main
|
|
|
|
var a string // global scope
|
|
|
|
func main() {
|
|
a = "G"
|
|
print(a)
|
|
f1()
|
|
}
|
|
func f1() {
|
|
a := "O" // new local variable a, only scoped within f1() !
|
|
print(a)
|
|
f2()
|
|
}
|
|
func f2() {
|
|
print(a) // global variable is taken
|
|
}
|
|
|
|
// GOG
|