title: How do you know how much space to allocate with malloc()?
body: <p>I'm a total C newbie, I come from C#. I've been learning about memory management and the <code>malloc()</code> function. I've also came across this code:</p>
  
  <pre><code>char *a_persons_name = malloc(sizeof(char) + 2);
  </code></pre>
  
  <p>What I don't understand is how much space this is allocating for <code>a_persons_name</code>. Is it allocating 2 characters (eg. AB) or something else? </p>
  
  <p>I also know that you can sometimes get "lucky" with <code>malloc</code> and use unallocated space (which can result in data corruption and seg faults). So how do I know how much space I'm allocating and how much I will need?</p>