title: Allocating string with malloc
body: <p>I'm new in programming in C and now I'm studying strings.
  My question is: if I allocate a string using <code>malloc</code> (as in the code below), is the NULL character automatically inserted at the end of the string?
  I find an answer in another question here, and it seems that the NULL character is not automatically included.
  But here comes the problem: I know functions like <code>strlen</code> don't work if there isn't the NULL character, and in this code I use it and it works. So I think there is <code>\0</code> at the end of my string, even if I don't write it anywhere.
  What's the answer?</p>
  
  <p>Here's the code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  int main(int argc, char** argv) {
      char *stringa1;
      int n;
      int i;
  
      printf("How many characters in the string? ");
      scanf("%d", &amp;n);
  
      stringa1 = (char*) malloc(n*sizeof(char));
  
      printf("Insert the string: ");
      scanf("%s", stringa1);
  
      free(stringa1);
  
      return 0;
  }
  </code></pre>