title: dynamically increase size of array (int*) in c
body: <p>i want to dynamically add numbers to an array in c. My idea is to just allocate a new array with size + 1, add the number, free the root array and change the pointer from the temp to the root array. Like this:</p>
  
  <pre><code>void addNumber(int* a, int* size, int number)
  {
      *size = *size + 1;
      int* temp = (int*)(calloc(*size, sizeof(int)));
      int i, j = 0;
      for(i = 0; i &lt; *size-1; i++) {
          if(a[i] &lt; number) {
              printf("add ai");
              temp[j] = a[i];
              j++;
          } else {
              printf("add number");
              temp[j] = number;
          }
      }
      if(j != *size) {
          printf("add new number");
          temp[j] = number;
      }
      free(a);
      a = temp;
  }
  
  int main(int argc, char* argv[])
  {
      int n = 10;
      int* a;
      int size = 1;
  
      a = (int*) (calloc(1, sizeof(int)));
      a[0] = 1;
  
      if(!contains(a, size, 2)) {
          addNumber(a, &amp;size, 2);
      }
  
      printArray(a,size);
  
      return 0;
  }
  </code></pre>
  
  <p>The problem is that in the addNumber function the code works and the *a has the right values of the new array. But in the main function the array *a has the values 1,0. So the new inserted value 2 is not added. Why? Can't get the reason.</p>