Please tell me why the

Test_GetNowfunction andprintPointerfunction output different addresses.
Since I was passing a pointer as an argument, I thought it would be the same address.

func Test_GetNow (test * testing.T) {
    tokyo, _: = time.LoadLocation ("Asia/Tokyo")
    t: = time.Now (). In (tokyo)
    var pt * time.Time =&t
    fmt.Printf ("GetNow:% v \ n",&pt)
    printPointer (pt)
func printPointer (t * time.Time) {
    fmt.Printf ("printPointer:% v \ n",&t)

Output result

GetNow: 0xc000086028
printPointer: 0xc000086030
  • Answer # 1

    Both are the same in the sense that they display the address of a variable of type** time.Time, but what is passed to the printPointer function is* time.Time.

    To get the same address,** time.Timetype should be taken as an argument as follows.

    func printPointerPointer (t ** time.Time) {
        fmt.Printf ("printPointerPointer:% p \ n", t)