Home > Backend Development > Golang > About the difference between & and * in go and its application scenarios

About the difference between & and * in go and its application scenarios

藏色散人
Release: 2021-02-22 14:15:20
forward
3320 people have browsed it

The following tutorial column will introduce to you the difference between go’s & and *, as well as application scenarios. I hope it will be helpful to friends in need! & In go, the address character is taken directly , but the second item returns &{} instead of 0x...Address

I don’t quite understand this

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}
Copy after login

The above is the detailed content of About the difference between & and * in go and its application scenarios. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template