title: How to allocate a non-constant sized array in Go
body: <p>How do you allocate an array in Go with a run-time size?</p>
  
  <p>The following code is illegal:</p>
  
  <pre><code> n := 1
   var a [n]int
  </code></pre>
  
  <p>you get the message <code>prog.go:12: invalid array bound n</code> (or similar), whereas this works fine:</p>
  
  <pre><code> const n = 1
   var a [n]int
  </code></pre>
  
  <p>The trouble is, I might not know the size of the array I want until run-time.</p>
  
  <p>(By the way, I first looked in the question <a href="https://stackoverflow.com/q/3387273/57171">How to implement resizable arrays in Go</a> for an answer, but that is a different question.)</p>