Go pointer

作者: JaedenKil | 来源:发表于2019-03-05 15:37 被阅读0次
    package main
    
    import "fmt"
    
    func main() {
    
        i, j := 42, 49
    
        p := &i // Set 'p' points to 'i'
        fmt.Println(*p) // Print 'i'
        *p = 21 // Set 'i' through the pointer 'p'
        fmt.Println(*p)
        fmt.Println(i)
        fmt.Println("---")
    
        p = &j // Set 'p' points to 'j'
        fmt.Println(*p)
        *p = *p / 7 // Device 'j' through the pointer 'p'
        fmt.Println(*p)
        fmt.Println(j)
    }
    

    Outputs:

    42
    21
    21
    ---
    49
    7
    7
    

    相关文章

      网友评论

        本文标题:Go pointer

        本文链接:https://www.haomeiwen.com/subject/jrhouqtx.html