type student struct { name string id int } func main() { stu := student{"wjc",11} test(&stu.id) fmt.Println(stu) } func test(id *int) { *id++ }
指针也可以用于struct的field。
Go复习--field指针
原文:https://www.cnblogs.com/wanjch/p/11517882.html