mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 05:33:04 +08:00
4.5.2.5.md
This commit is contained in:
19
eBook/exercises/chapter_4/global_scope.go
Normal file
19
eBook/exercises/chapter_4/global_scope.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
var a = "G" // global scope
|
||||
|
||||
func main() {
|
||||
n()
|
||||
m()
|
||||
n()
|
||||
}
|
||||
|
||||
func n() {
|
||||
print(a)
|
||||
}
|
||||
|
||||
func m() {
|
||||
a = "O" // simple assignment: global a gets a new value
|
||||
print(a)
|
||||
}
|
||||
// GOO
|
Reference in New Issue
Block a user