title: Why can an array inside a function be longer than an array inside main function in c?
body: <p>array[4] is an array of 4 length. Passing array and 4 to function read_line, the array str[] would be an array of 4 length so the array could only hold a character up to str[3], I thought.</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  int read_line(char str[], int n);
  
  int main(void)
  {
     char array[4];
  
     read_line(array, 4);
  
     printf(&quot;%s\n&quot;, array);
  
     return 0;
  }
  
  int read_line(char str[], int n)
  {
      int ch, i = 0;
  
      while ((ch = getchar()) != '\n')
          if (i &lt; n)             
            str[i++] = ch;
      str[i] = '\0';
  
      return i;
  }
  </code></pre>
  <p>But when I entered four characters like abcd, it runs without any error.</p>
  <pre><code>abcd
  </code></pre>
  <p>Why can the array str[] hold '\0' in str[4]?</p>