title: C program ：insert an element at the end of an array
body: <p>I would like to add an element at the end of the array. LENGTH(a) is a marco which means the size of the array <code>a</code> . Initial value of the array is {1}. I would like to add all even-number into array.So,the result I want is array = {1,0,2,4},but the result is as the picture shows.</p>
  <p><img src="https://i.stack.imgur.com/9jBG6.png" alt="enter image description here" /></p>
  <p>The code is as follows：</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define LENGTH(a) (sizeof(a) / sizeof(*a))
  
  void insert(int *, int);
  
  void main(){
      int size = 1;
      int * array = (int*)malloc(size * sizeof(int));
      array[0] = 1;
      int i;
      int value = 0;
  
      for(i = 0; i &lt; 5; i++){
          if (i%2 == 0){
              insert(array, i);   
          }       
      }
      for(i = 0; i &lt; LENGTH(array); i++) {
        printf(&quot;array[%d] = %d\n&quot;, i, array[i]);
     }
  }
  
  void insert(int *array, int a){
      array = realloc(array, (LENGTH(array)+1)*sizeof(int));
      printf(&quot;length = %d\n&quot;, LENGTH(array));
      array[LENGTH(array)] = a;   
  }
  </code></pre>
  <p>I'd like to know why this occurs and how to solve it.</p>