title: How to get the underlying array of a slice in Go?
body: <p>Let's say I have the following array of ints of length 3:</p>
  
  <p><code>nums := [3]int{1,2,3}</code></p>
  
  <p>Then I grab the slice of just the first two items</p>
  
  <p><code>numSlice := nums[:2]</code></p>
  
  <p>Invoking <code>cap</code> on numSlice and nums yields 3 in both cases, and <code>len</code> yields 2 and 3 respectively.</p>
  
  <p>If I then append to that slice (<code>numSlice = append(numSlice, 10)</code>), the underlying array (<code>nums</code>) is now <code>[1 2 10]</code>. <code>cap</code> remains at 3 for both, as the underlying array of the slice is the same, and len for the slice is now 3.</p>
  
  <p>However, if I append to that slice again (<code>numSlice = append(numSlice, 20)</code>), the underlying array of the slice must change - we see this is the case when <code>cap</code> now has doubled for numSlice and len is now 4. </p>
  
  <p>Sorry for the overwrought explanation, just walking myself through it, but can someone explain to me what happens under the hood to the underlying array and how to get the reference to the new array? </p>