title: malloc vs array in C
body: <p>I am taking an open online course <a href="https://www.edx.org/course/introduction-computer-science-harvardx-cs50x#!" rel="noreferrer">CS50</a> from Harvard. The last lecture I had was about memory allocation and pointers (two concepts which are absolutely new to me). </p>
  
  <p>What was taught is that <code>malloc(10*sizeof(char))</code> allocates enough bytes on the heap to store 10 characters and returns a pointer to the first byte which can be saved in another variable as follows <code>char *x = malloc(10*sizeof(char))</code>. To free the memory one would use <code>free(x)</code>. </p>
  
  <p>But there is another way to make a computer to reserve enough memory to store 10 characters i.e. <code>char c[10]</code>.</p>
  
  <ol>
  <li>Is in the code snippet above <code>c</code> also a pointer of type <code>char*</code>?</li>
  <li>Does <code>char c[10]</code> also reserve memory <strong>on the heap</strong> as <code>malloc</code> does?</li>
  <li>Are the ways to allocate memory equivalent?</li>
  <li><code>char c[3] = "aaa";free(c);</code> returns a runtime error; so it seems I can not free the memory I have allocated with <code>char c[3]</code>. Why is that?</li>
  </ol>
  
  <p>I would really appreciate an answer tailored to somebody who just have learned about pointers. </p>