package main
import "fmt"
func main() {
i, j := 42, 49
p := &i // Set 'p' points to 'i'
fmt.Println(*p) // Print 'i'
*p = 21 // Set 'i' through the pointer 'p'
fmt.Println(*p)
fmt.Println(i)
fmt.Println("---")
p = &j // Set 'p' points to 'j'
fmt.Println(*p)
*p = *p / 7 // Device 'j' through the pointer 'p'
fmt.Println(*p)
fmt.Println(j)
}
Outputs:
42
21
21
---
49
7
7
网友评论