package main
import (
"fmt"
)
var x = "hello"
func change() {
x = "world"
}
func main() {
fmt.Println(x)
change()
fmt.Println(x)
}
结果是:
hello
world
package main
import (
"fmt"
)
var x = "hello"
func change(y string) {
y = "world"
}
func main() {
fmt.Println(x)
change(x)
fmt.Println(x)
}
运行结果:
hello
hello