title: append to dynamically allocated array in c
body: <p>I try realloc but it didn't work</p>
  
  <p>this is the code. thanks for your help</p>
  
  <pre><code>trial = malloc (4 * sizeof(int));
  
  trial[0] = 1; trial[1] = 4;trial[2] = 7;trial[3] = 11;
  
  trial = (int*)realloc(trial, sizeof(int) * 5);
  trial[sizeof(trial)-1] = 23;
  
  int a;
  for(a = 0; a &lt; sizeof(trial); a++){
          printf("TRIAL %d \n", trial[a]);
  }
  </code></pre>
  
  <p>And the output look like this</p>
  
  <pre><code>TRIAL 1 
  TRIAL 4 
  TRIAL 7 
  TRIAL 23 
  </code></pre>
  
  <p>It should be</p>
  
  <pre><code>TRIAL 1 
  TRIAL 4 
  TRIAL 7 
  TRIAL 11
  TRIAL 23 
  </code></pre>