//参考 https://segmentfault.com/a/1190000012214571
//参考 https://studygolang.com/articles/2215
func bar()(name string){
//use p
fmt.Println("xxx",p)
for i := 0; i<10; i++{
var name = "test"
fmt.Println(name)
}
//name = "xx"
fmt.Println("name is ", name) //此时name为""
return
//fmt.Println(*p)
}
//-----------------
//testpointer.go
package main
import (
"fmt"
)
var p *int
func foo() (*int, error) {
var i int = 5
return &i, nil
}
func bar() {
//use p
fmt.Println(*p)
}
func main() {
//var err error
p, err := foo() //p, err = foo( )
if err != nil {
fmt.Println(err)
return
}
bar()
fmt.Println(*p)
}