How does the append function work when the underlying array reaches its capacity, and how does the growth factor change as the slice gets larger?

Last updated 20 June 2026

  • When len == cap, append allocates a larger backing array, copies the elements, and returns a new slice. That is why you must write s = append(s, x).

  • Growth is about 2x for small slices and tapers toward ~1.25x above ~256 elements, so appends stay amortized O(1) without wasting memory.

  • Preallocate with make([]T, 0, n) when the size is known to avoid repeated reallocations.

  • https://www.reddit.com/r/rust/comments/1h15md8/goodbye_rust_i_wish_you_success_but_im_back_to_c/
  • https://www.reddit.com/r/golang/comments/1gfjnzm/since_when_is_senior_golang_developer_expected_to/
All Golang interview questions