// Array and slice copying in Go package main import "fmt" type AA struct { ab int ac int } func main(){ ott() } func ott(){ // First Arrays // make array aa := [3]AA{ } fmt.Println(aa) bb := aa // copy array fmt.Printf("aa %p bb %p\n", &aa, &bb) // the array and the copy are totally different things for i,_ := range aa { fmt.Printf("%d aa %p bb %p\n", i, &aa[i], &bb[i]) } // now make a slice sl1 := make([]AA, 5) sl2 := sl1 // copy the slice // based on pointer, they are different fmt.Printf("sl1 %p sl2 %p\n", &sl1, &sl2) // but their contents are identical for i,_ := range sl1 { fmt.Printf("%d sl1 %p sl2 %p\n", i, &sl1[i], &sl2[i]) } sl3 := sl2[0:2] // make a subslice // again, its contents are identical. for i,_ := range sl3 { fmt.Printf("%d sl3 %p \n", i, &sl3[i]) } }