小兔网

下面由golang教程栏目给大家介绍go的 & 和 * 的区别,以及应用场景 ,希望对需要的朋友有所帮助!

& 在go中是直接取地址符

但是在第二项返回的是&{} 而不是0x…地址

这个就不太理解了

package mainimport "fmt"type Test struct {    name string}func main() {    test := Test{"test"}    fmt.Println(test)    //结果{test}    testa := &Test{"test"}    fmt.Println(testa)    //结果 &{test}    testc := &Test{"test"}    fmt.Println(*testc)    //结果 {test}    testd := &Test{"test"}    fmt.Println(&testd)    //结果 0xc000006030}

以上就是关于go的&和*的区别以及应用场景的知识。速戳>>知识兔学习精品课!