3 ms·
It's because slices have underlying arrays which define their capacity (cap(s)). Both slices start out having the same underlying (bigger) array -so appending
by geoka9 2y ago
It's because slices have underlying arrays which define their capacity (cap(s)).
Both slices start out having the same underlying (bigger) array -so appending to one slice can affect the other one.
In the "bonus" part, though, the appends outgrew the original array, so new underlying arrays were allocated (i.e. the slices stopped sharing the same backing array).
Thanks for the heads-up, janosdebugs :)