'why golang array append twice use singletion object
In Golang i run program like this:
r1 := []string{"first"}
r1 = append(r1, "second")
r1 = append(r1, "third")
fmt.Println(r1)
r2 := append(r1, "f1")
r3 := append(r1, "f2")
fmt.Println(r2, r3)
[first second third]
[first second third f2] [first second third f2]
my question is append seems return singleton object when array not resize, so r2 r3 is same.
if array resize, r2 r3 are different object, r2 r3 is different.
same code run different result, it makes me confused.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
