Mastering-Go-Second-Edition/ch03/pointers.go
Mihalis Tsoukalos a39cfd0b05 ch03 + ch04
2019-01-10 22:08:08 +02:00

38 lines
457 B
Go

package main
import (
"fmt"
)
func getPointer(n *int) {
*n = *n * *n
}
func returnPointer(n int) *int {
v := n * n
return &v
}
func main() {
i := -10
j := 25
pI := &i
pJ := &j
fmt.Println("pI memory:", pI)
fmt.Println("pJ memory:", pJ)
fmt.Println("pI value:", *pI)
fmt.Println("pJ value:", *pJ)
*pI = 123456
*pI--
fmt.Println("i:", i)
getPointer(pJ)
fmt.Println("j:", j)
k := returnPointer(12)
fmt.Println(*k)
fmt.Println(k)
}