package main
import (
"fmt"
"unsafe"
)
func main() {
var value int64 = 5
var p1 = &value
var p2 = (*int32)(unsafe.Pointer(p1))
fmt.Println("*p1: ", *p1)
fmt.Println("*p2: ", *p2)
*p1 = 5434123412312431212
fmt.Println(value)
fmt.Println("*p2: ", *p2)
*p1 = 54341234
fmt.Println(value)
fmt.Println("*p2: ", *p2)
}
返回指针
package main
import (
"fmt"
)
func returnPtr(x int) *int {
y := x * x
return &y
}
func main() {
sq := returnPtr(10)
fmt.Println("sq:", *sq)
fmt.Println("sq:", sq)
}
网友评论