When you use append, two different things can happen:

1. There is enough capacity in the original slice to which you are 
appending to add the additional values. You get a slice that points to the 
same backing memory.
2. There is not enough capacity in the original slice to which you are 
appending. You get a slice that points to a newly allocated chunk of 
backing memory.

This blog talks specifically about append: https://blog.golang.org/slices

Now, looking at your code:

  
    c1 := append(c, s)
    temp = append(temp, c1)
    fmt.Println(i,j,k, "- temp =", temp, " c=", c)

The key thing to see here, is that s is going to be added to c, and *c* is 
going to end up in c1, IF there is enough room for s in c. So, sometimes c1 
is pointing to the same bit of memory as c, sometimes a different bit.

I think, rather than making a copy of the temp variable c1, you should be 
doing the same thing at the step where you create c1.

In other words, something like
c1 := append([]int{}, c..., s)

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to