首页 > 其他 > 详细

structs _ golang

时间:2015-03-14 18:26:21      阅读:328      评论:0      收藏:0      [点我收藏+]

Go‘s structs are typed collections of fields. They‘re useful for grouping data together to form records

package main

import (
    "fmt"
)

type person struct {
    name string
    age  int
}

func main() {

    fmt.Println(person{"Bob", 20})
    fmt.Println(person{name: "Alice", age: 30})
    fmt.Println(person{name: "Fred"})

    fmt.Println(&person{name: "Ann", age: 40})

    s := person{name: "Sean", age: 50}
    fmt.Println(s.name)

    sp := &s

    fmt.Println(sp.age)

    sp.age = 51

    fmt.Println(sp.age)

}
{Bob 20}
{Alice 30}
{Fred 0}
&{Ann 40}
Sean
50

总结 :

  1 : 通过 & 能得出 struct 的指针

    2 :  You can also use dots with struct pointers - the pointers are automatically dereferenced

structs _ golang

原文:http://www.cnblogs.com/jackkiexu/p/4337927.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!