title: Why does gcc allow char array initialization with string literal larger than array?
body: <pre><code>int main()
  {
      char a[7] = "Network";
      return 0;
  }
  </code></pre>
  
  <p>A <strong>string literal</strong> in C is terminated internally with a <strong>nul character</strong>. So, the above code should give a compilation error since the actual length of the string literal <code>Network</code> is 8 and it cannot fit in a <code>char[7]</code> array.</p>
  
  <p>However, <strong>gcc</strong> (even with <code>-Wall</code>) on Ubuntu compiles this code without any error or warning.
  Why does gcc allow this and not flag it as compilation error?</p>
  
  <p>gcc only gives a warning (still no error!) when the char array size is smaller than the string literal. For example, it warns on:</p>
  
  <pre><code>char a[6] = "Network";
  </code></pre>
  
  <p>[Related] <strong>Visual C++ 2012</strong> gives a compilation error for <code>char a[7]</code>:</p>
  
  <pre><code>1&gt;d:\main.cpp(3): error C2117: 'a' : array bounds overflow
  1&gt; d:\main.cpp(3) : see declaration of 'a'
  </code></pre>