title: why do i get segmentation fault in 1st code but not in 2nd code?
body: <p>I have declared an array of 10 pointers to characters.out of 10 I have initialised only 3.
  When I print the array using <code>%s</code> following <code>\n</code> then it gives output as follows:</p>
  
  <pre><code>hi
  hello
  how 
  segmentation fault
  </code></pre>
  
  <p>but if I dont use <code>\n</code> then it gives output as follows:</p>
  
  <pre><code>hihellohow(null)...(7 times).
  </code></pre>
  
  <p>can somebody explain this please? </p>
  
  <hr>
  
  <p><strong>CODE 1</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void main()
  {
      char *a[10] = {"hi", "hello", "how"};
      int i = 0, j = 0;
  
      a[0] = "hey";
      for (i = 0;i &lt; 10; i++)
          printf("%s\n", a[i]);
  }
  </code></pre>
  
  <p><strong>CODE 2</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void main()
  {
      char *a[10] = {"hi", "hello", "how"};
      int i = 0, j = 0;
  
      a[0] = "hey";
      for (i = 0;i &lt; 10; i++)
          printf("%s", a[i]);
  }
  </code></pre>