title: Returning all even numbers found in an array
body: <p>I am trying to create a program that goes as follows: The user is asked to enter the length for an array. The array is then created and filled with random numbers, its lentgh being that which the user specified in the beginning. After that, I must creat a function named <code>getEvenNumbers</code>, in which I determine which numbers in the array are even. Once that has been completed, my <code>int main</code> calls <code>getEvenNumbers</code> and prints all the even numbers found. Here is the code I have so far:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  
  void getEvenNumbers(int *, int *);
  
  int main()
  {
      int i, j, k, N, w, size, *tab, *tabPtr = 0, *sizePtr = 0;
  
      printf("Enter the desired length of the array: ");
      scanf("%d", &amp;N);
  
      size = N;
  
      sizePtr = &amp;size;
  
      tab = (int *)malloc(sizeof(int)*size);
  
      srand(time(0));
  
      for(i = 0; i &lt; size; i++)
      {
          j = rand();
          tab[i] = j;
      }
  
      tabPtr = &amp;tab[0];
  
      printf("The array created is:\n");
      for(k = 0; k &lt; size; k++)
          printf("%d\t", *(tabPtr+k));
  
      printf("\n\n");
  
      getEvenNumbers(tabPtr, sizePtr);
      printf("The pair numbers are:\n");
      for(w = 0; w &lt; *sizePtr; w++)
          printf("%d\t",*(tabPtr+w));
  
      return 0;
  }
  
  void getEvenNumbers(int *tab, int *sizePtr)
  {
      int i = 0, w = 0;
  
      for(i = 0; i &lt; *sizePtr; i++)
      {
          if(tab[i]%2 == 0)
          {
              tab[w] = tab[i];
              w++;
          }
      }
  }
  </code></pre>
  
  <p>I have successfully created the random array of any given length. However, I am struggling to return all the even numbers in that array. Could someone shed some light on why this doesn't return only even numbers?</p>