21_Go基础(pointer)

package main

import (
    "fmt"
)

func main() {

    // & 取地址
    // * 根据地址取值
    n1 := 10
    p1 := &n1
    fmt.Println(p1)        // 0xc000014098
    fmt.Printf("%T
", p1) // *int
    fmt.Println(*p1)       // 10

    // 分配一块内存地址
    p := new(int)
    *p = 100
    fmt.Println(p, *p) // 0xc0000aa0a0 100
}
原文地址:https://www.cnblogs.com/luwei0915/p/15357638.html