go是如何分配記憶體的?

chenqinghe發表於2016-10-13
func main() {
    a := 1
    b := 2
    c := "hello world"
    d := 1
    fmt.Printf("var a address is %p\n", &a)//var a address is 0xc0420361d0
    fmt.Printf("var b address is %p\n", &b)//var b address is 0xc0420361d8
    fmt.Printf("var c address is %p\n", &c)//var c address is 0xc0420361e0
    fmt.Printf("var d address is %p\n", &d)//var d address is 0xc0420361f0

}

變數 c 的大小明顯超過了 2B,為什麼還是隻佔了 2B 的長度?golang 的變數記憶體是如何分配的?

更多原創文章乾貨分享,請關注公眾號
  • go是如何分配記憶體的?
  • 加微信實戰群請加微信(註明:實戰群):gocnio

相關文章