title: C: Return even number in array program by using pointers, why does my program crush after printing the result
body: <p>This is my simple program that generate a array of N integers, print it, and it will call the getevennumber function, and the function will return the pointer addresses of the even numbers in array. and the main program will print the even numbers in the array:</p>
  
  <pre><code>    #include &lt;stdio.h&gt;
      int* getEvenNumber(int a[]);
  
      int main (){
          int N;
          printf("Enter N: ");
          scanf("%d", &amp;N);
          int array[N], i;
          int *test[N];
          srand(time(NULL));
          for(i = 0; i &lt; N; i++)
          {
  
              array[i] = (rand() % 100)+1;
              printf("%d \n", array[i]);
  
          }
          printf("------- \n");
          *test = getEvenNumber(array);
          for(i = 0; i &lt;= sizeof(test); i++){
              printf("%d \n", *test[i] );
          }
  
  
          return 0;
      }
  
      int* getEvenNumber(int a[]){
          int i,j = 0;
          int* ptr[j];
          for(i = 0; i  &lt;= sizeof(a); i++)
          {
  
           if (a[i] % 2 == 0)
              {
                 ptr[j] = &amp;a[i];
                 printf("%d\n",*ptr[j]);
                 j++;
             }
          }
           return *ptr;
  
      }
  </code></pre>
  
  <p>currently the problem is: when I run the program, it will print the desired even numbers, then the program will also print 2 random data address then crushes, here is an example output:</p>
  
  <p>N: 10<br>
  66<br>
  19<br>
  70<br>
  54<br>
  84<br>
  12<br>
  35<br>
  56<br>
  53<br>
  19  </p>
  
  <hr>
  
  <p>66<br>
  70<br>
  54<br>
  84<br>
  19<br>
  1981890690<br>
  -1090571325<br>
  (program crushed)</p>
  
  <p>Can someone help me identify the problem please, thank you!</p>