码迷,mamicode.com
首页 > 其他好文 > 详细

A Tour of Go Pointers

时间:2014-10-27 00:18:05      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   sp   div   on   log   

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)
}

 

A Tour of Go Pointers

标签:style   blog   color   io   ar   sp   div   on   log   

原文地址:http://www.cnblogs.com/ghgyj/p/4053062.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!