title: Both these simple codes in C are identical but I am getting different outputs. Would love some introspection
body: <p>Both these simple codes in C are identical but I am getting different outputs. Would love some introspection</p>
  
  <p>The output of first code is correct, it is what i was expecting only i don't understand why output changes by commenting a printf statement, but this is simple only i don't understand the logic even after debugging it, the outputs should be same in both codes as they are same, any help on returning array from functions to main and then printing those arrays would help me.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int* func ()
  {
      int a[3] = { 1, 2, 3};
      printf ("size: %d\n", sizeof(a[2]));
      return a;
  }
  
  int main()
  {
      int *b, c, i;
  
      b = func ();
  
      for (i=0; i&lt;3; i++)
      {
          printf ("%d\n", *b + i);
      }
  
      return 0;
  }
  </code></pre>
  
  <p><strong>Output:</strong>
  size: 4</p>
  
  <p>1</p>
  
  <p>2</p>
  
  <p>3</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int* func ()
  {
      int a[3] = { 1, 2, 3};
      //printf ("size: %d\n", sizeof(a[2]));
      return a;
  }
  
  int main()
  {
      int *b, c, i;
  
      b = func ();
  
      for (i=0; i&lt;3; i++)
      {
          printf ("%d\n", *b + i);
      }
  
      return 0;
  }
  </code></pre>
  
  <p><strong>Output:</strong>
  1</p>
  
  <p>1962249430</p>
  
  <p>1962249431</p>