title: C Array Instantiation - Stack or Heap Allocation?
body: <p>I guarantee that this question has been asked before, but I haven't been able to find it via search; sorry in advance for any redundancies.</p>
  
  <p>It's my (potentially wrong) understanding that you only allocate to the stack when you know the size of an object at compile time. So in the case of initializing an array, you could do one of these (and this should go on the stack):</p>
  
  <pre><code>char charArray[50];
  </code></pre>
  
  <p>Since the size of this array is known at compile time, this should have no issues.</p>
  
  <p>On the other hand, this (I believe) is also valid code:</p>
  
  <pre><code>char anotherCharArray[someVariable + 50];
  </code></pre>
  
  <p>Would this go on the stack as well? I am pretty sure the code segfaults if you free() this, so it makes me think it does, but it doesn't really make sense to me. Similarly, is the 100% sole situation where you have to use free() when the data was allocated via malloc?</p>
  
  <p>Thanks in advance for your help.</p>