package main import "fmt" type Student struct { Name string Age int } func main() { data := make([]*Student, 0) src := []Student{ Student{Name: "allen", Age: 30}, Student{Name: "tom", Age: 33}, } for _, m := range src { data = append(data, &m) } for _, s := range data { fmt.Println(*s) } }
输出结果:
{tom 33}
{tom 33}
不是:
{allen 30}
{tom 33}