How do I print the pointer value of a Go object? What does the pointer value mean?

后端 未结 5 1375
野的像风
野的像风 2020-12-12 11:24

I am just playing around with Go and do not yet have a good mental model of when structs are passed by value or by reference.

This may be a very dumb question but I

5条回答
  •  攒了一身酷
    2020-12-12 12:13

    How do I print the pointer value of a Go object?

    package main
    
    import (
        "fmt"
    )
    
    func main() {
        a := 42
        fmt.Println(&a)
    }
    

    results in:

    0x1040a124
    

    What does the pointer value mean?

    According to Wikipedia:

    A pointer references a location in memory

提交回复
热议问题