title: Why is the 3rd element initialized to a garbage value?
body: <p>I am playing around with basic memory allocation with arrays in C using Xcode.</p>
  <p>Here's my code:</p>
  <pre><code>   int *arr; // creating pointer
  
  arr=(int*) malloc(3*sizeof(int)); // allocating memory in heap
  
  printf(&quot;%d\n&quot;, arr[0]);
  printf(&quot;%d\n&quot;, arr[1]);
  printf(&quot;%d\n&quot;, arr[2]);
  
  int a = 3;
  int b = 4;
  int c = 5;
  
  
  arr[0] = a;
  arr[1] = b;
  arr[2] = c;
  
  printf(&quot;%d\n&quot;, arr[0]);
  printf(&quot;%d\n&quot;, arr[1]);
  printf(&quot;%d\n&quot;, arr[2]);
  </code></pre>
  <p>The output I get is:</p>
  <p>0<br />
  0<br />
  268744246<br />
  3<br />
  4<br />
  5</p>
  <p>Why is the 3rd value initialized to 268744246 and not 0 like the first two values?</p>