dongliu5475
2014-09-02 13:11 阅读 49
已采纳

Golang-内部的Struct如何实现?

I'm quite confusing about the struct in Go.

This is the code: http://play.golang.org/p/b1NEh7JZoK

Why I could't get the address of a variable to a struct?

If I have two int variables, one stores value, one stores address(pointer), like this : http://play.golang.org/p/XhvKX-ifdn

I can get the actual address of these two variables, but why struct can't?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dongliang9576 dongliang9576 2014-09-02 13:16

    fmt.Println prints things in a more readable format. If you want to actually see the addresses, use fmt.Printf with %p verb:

    fmt.Printf("%p
    ", &a)          // 0x10328000
    fmt.Printf("%p -> %p
    ", &b, b) // 0x1030e0c0 -> 0x10328000
    

    Playground.

    点赞 评论 复制链接分享

相关推荐