title: not able to understand char malloc() in c
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
      char* id;                                          
      int n;
      printf(&quot;enter the no of char you want\n&quot;);
      scanf(&quot;%d&quot;, &amp;n);
      id = (char*)malloc((n+1)*sizeof(char));
      printf(&quot;enter the id\n&quot;);
      scanf(&quot;%s&quot;, id);
      printf(&quot;%s\n&quot;, id);
  }
  </code></pre>
  <p>I am not able to understand this.
  I allocate memory of my desired length. Then I take a string as input (which otherwise not allowed) how is this possible and I am able to write more than the allocated chars and it is still printing.</p>