package main
import "fmt"
func main(){
p1:=test()
p2:=test()
fmt.Println(p1(),p2(),p1())
}
func test() func ()int {
t:=0
return func() int {
tPP
return t
}
}
the above is one of my exercises, but the return result is a little different from what I expected. The return result is: 1 br 2. Can someone give me some advice? I think the return value should be 1 minute 1.
my question:
1. When you finish executing p1:=test (), you can get the result:
p1:=func()int{
tPP
return t
}
when executing p1 (), t within the function belongs to the local variable of the function test (). Why can p1 () still be used?
2. The first execution of p1 (), and then the execution of p1 () why t will accumulate, in fact, this is essentially the same as the first question.
the above is what I don"t understand. I hope you can give me some advice. I am a novice in Go learning. The question may be a little simple. I hope you will understand.