1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| type User struct { id uint name string }
func main() { var arg uint16 = 30 result := receivePointerFunc(arg) fmt.Println("receivePointerFunc result is", result) fmt.Println("receivePointerFunc resultValue is", *result) fmt.Println("final arg is", arg)
var arg2 uint16 = 10 result = receivePointerFunc2(&arg2) fmt.Println("receivePointerFunc2 result is", result) fmt.Println("receivePointerFunc2 resultValue is", *result) fmt.Println("final arg2 is", arg2)
var arg3 uint16 = 30 result2 := normalFunc(arg3) fmt.Println("normalFunc result addr is", &result2)
var user = User{} user.id = 1 user.name = "delryn" fmt.Println("user is", user) result3 := receiveStructPointerFunc(user) fmt.Println("receiveStructPointerFunc result is", result3) fmt.Println("final user is", user) }
func receivePointerFunc(param uint16) *uint16 { fmt.Println("receivePointerFunc param is", param) param += 10 fmt.Println("receivePointerFunc param addr is", ¶m) return ¶m }
func receivePointerFunc2(param *uint16) *uint16 { fmt.Println("receivePointerFunc2 param is", param) *param += 100 return param }
func normalFunc(param uint16) uint16 { param += 10 fmt.Println("normalFunc param addr is", ¶m) return param }
func receiveStructPointerFunc(user User) *User { user.id += 1 fmt.Println("receiveStructPointerFunc user is", user) return &user }
|