A Tour of Go Pointers

Go has pointers, but no pointer arithmetic.

Struct fields can be accessed through a struct pointer. The indirection through the pointer is transparent.

 

package main  

import "fmt"

type Vertex struct {
    X int
    Y int
}

func main() {
    p := Vertex{1, 2}
    var q2 *Vertex = &p
    fmt.Println(q2.X)
    q := &p
    q.X = 1e9
    fmt.Println(p)
}

 

posted @ 2014-10-26 23:30  wuhn  阅读(128)  评论(0编辑  收藏  举报