package main import ( "fmt" ) type Vertex struct { X, Y int } func dop(a Vertex, vl int) { a.X = vl fmt.Println(a.X) } func dopwithptr(a *Vertex, vl int) { a.X = vl fmt.Println(a.X) } func (a *Vertex) dopptr(vl int) { a.X = vl fmt.Println(a.X) } func main() { //解释:":="这个符号是自动匹配类型,比如 a := 100, //会把右边的类型和值传递到变量a,也就是说a的类型是int,值是100 var d Vertex dop(d, 8) fmt.Println(d) v := new(Vertex) v.dopptr(9) fmt.Println(v) dopwithptr(v, 11) fmt.Println(v) dopwithptr(&d, 12) fmt.Println(d) (&d).dopptr(13) fmt.Println(d) } //返回值 8 {0 0} 9 &{9 0} 11 &{11 0} 12 {12 0} 13 {13 0}