It generates a new append copies pointer passed by reference 1. The package main
Import ( " FMT " ) FUNC W (S [] int ) [] int { fmt.Printf ( " in # V% V% W " , S, S & [ 0 ])
// append s after the designated pointer to the new memory copy , no longer point to the original memory S = the append (S, 0 ) fmt.Printf ( " After the append # V% V% W " , S, S & [ 0 ]) return S } FUNC main () { S: = [ ] int { . 1 } fmt.Printf ( " OUT of # V% V% W " , S, S & [ 0]) S2: = W (s)
content // s original pointer remains in memory, instead of being covered / GC of fmt.Printf ( " After W V% V%%% # V # V " , s, S & [ 0 ], S2, S2 & [ 0 ]) }
output:
out of w [1] (*int)(0x40e020) in w [1] (*int)(0x40e020) after append w [1 0] (*int)(0x40e040) after w [1] (*int)(0x40e020) [1 0] (*int)(0x40e040)