title: Why is below two codes provide different results?
body: <ol>
  <li><p>The first piece of code is:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  char *getString()
  {
      char *str = "Will I be printed?";
      return str;
  }
  int main()
  {
      printf("%s", getString());
  }
  </code></pre></li>
  <li><p>And the second piece of code is:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  char *getString()
  {
      char str[] = "Will I be printed?";
      return str;
  }
  int main()
  {
      printf("%s", getString());
  }
  </code></pre></li>
  </ol>
  
  <p>In both of the above codes,char pointer is returned which points to a local variable which could get overwritten but still code-1 manages to run successfully while code-2 print Garbage values. </p>