乐趣区

关于golang:go变量

package main

import (
    "fmt"
    "reflect"
    "unsafe"
)

func main() {
    var s1, s2 string
    var sh1, sh2 *reflect.StringHeader
    s1 = "abcd"
    s2 = s1

    sh1 = (*reflect.StringHeader)(unsafe.Pointer(&s1))
    fmt.Println(sh1.Data, sh1.Len, &s1)

    sh2 = (*reflect.StringHeader)(unsafe.Pointer(&s2))
    fmt.Println(sh2.Data, sh2.Len, &s2)

    s2 = "cdef123"

    sh2 = (*reflect.StringHeader)(unsafe.Pointer(&s2))
    fmt.Println(sh2.Data, sh2.Len, &s2)

}
退出移动版