```go
package main
import (
"fmt"
"time"
)
func main() {
var num = 10
var p = &num
c := make(chan int)
go func() {
time.Sleep(time.Second)
c <- *p //-----> 11
//c <- num //----->10
}()
time.Sleep(2 * time.Second)
num++
fmt.Println(<-c)
fmt.Println(p)
return
}
```
为什么 *p 和num的结果不一样
package main
import (
"fmt"
)
func main() {
var num = 10
var p = &num
c := make(chan int)
c1 := make(chan int)
c2 := make(chan int)
go func() {
for {
select {
case c <- *p:
return
case c2 <- <-c1:
}
}
}()
c1 <- 1
num++
fmt.Println(<-c)
fmt.Println(num)
}
#13
更多评论