title: Initializing array of integer pointer in C
body: <p>I have some confusions/problems about the usage of pointers in C. I've put the example code below to understand it easily. Please notice differences of these codes. If you have some problem understanding it, please have a feedback.</p>
  
  <p>This doesn't work.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void process() {
      int *arr;
      arr=(int*)malloc(5*sizeof(int));
      arr=(int*){3,1,4,5,2};
      for(int z=0;z&lt;5;z++) {
          printf("%d ",arr[z]);
      }
      printf("\n");
  }
  
  int main() {
      process();
      return 0;
  }
  </code></pre>
  
  <p>But this works.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void process() {
      int *arr;
      arr=(int*)malloc(5*sizeof(int));
      arr=(int[]){3,1,4,5,2};
      for(int z=0;z&lt;5;z++) {
          printf("%d ",arr[z]);
      }
      printf("\n");
  }
  
  int main() {
      process();
      return 0;
  }
  </code></pre>
  
  <p>This also works too. Why? I didn't allocate memory here.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void process() {
      int *arr;
      arr=(int[]){3,1,4,5,2};
      for(int z=0;z&lt;5;z++) {
          printf("%d ",arr[z]);
      }
      printf("\n");
  }
  
  int main() {
      process();
      return 0;
  }
  </code></pre>
  
  <p>Why aren't they same?</p>
  
  <pre><code>    arr=(int*){3,1,4,5,2};
      arr=(int[]){3,1,4,5,2};
  </code></pre>
  
  <p>Is there any other way to initializing array of integer pointer, not using in this individual assigning way?</p>
  
  <pre><code>arr[0]=3;
  arr[1]=1;
  arr[2]=4;
  arr[3]=5;
  arr[4]=2;
  </code></pre>
  
  <p>How can i get the size/number of allocation in memory of pointer so that i can use something like <code>for(int z=0;z&lt;NUM;z++) {</code> instead of <code>for(int z=0;z&lt;5;z++) {</code> statically?</p>
  
  <p>Any answer is highly appreciated.</p>
  
  <p>Thanks in advance.</p>