title: invalid pointer in realloc
body: <p>This error never appeared before, I don't understand why it is happening. I am creating a C program to create an array and then realloc it to add more elements. Im applying many unecessary concepts in the same program to condense some knowledge.</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdbool.h&gt;
  
    // ALWAYS when doing a definition of new elements in a arrays, NEVER use size as a parameter
    // because if you assign one element as one, it will reset the value of size then reseting 
    // size &lt; sizenew.
    // Ex: Do not do:
    //
    // for (size; size &lt; newsize; size++) scanf (&quot;%hu&quot;, &amp;size)
    //
    // the number you choose for scanf will affect the number of times the loop will do, because size
    // is a parameter of while 
   
  
  int main()
  {
    _Bool decision;
    int* array;
    unsigned short size, newelements, oldsize, add, minus_oldsize, newsize, i, j;
  
    printf(&quot;Hello! put the size of the initial int array!\n&quot;);
    scanf(&quot;%hu&quot;, &amp;size);
    
    array = malloc(size * 4);
  
    printf(&quot;Put the array elements one by one\n&quot;);
    for (i = 0; i &lt; size; i++) scanf(&quot;%d&quot;, array + i);
  
    printf(&quot;This is your array:\n&quot;);
    for (j = 0; j &lt; size; j++) printf(&quot;%d\n&quot;, *(array + j));
  
    printf(&quot;Do you want to add more elements? no(0) yes(1)\n&quot;);
    scanf(&quot;%d&quot;, &amp;decision);
    if (decision != 1) return -1;
  
    printf(&quot;How many elements you want to add?\n&quot;);
    scanf(&quot;%d&quot;, &amp;newelements);
    newsize = size + newelements;
  
    array = realloc(array, newsize * 4);
  
    free(array);
    
    return 0;
  }
  </code></pre>
  <p>error:
  <code>realloc(): invalid pointer</code></p>