title: Function returning garbage values but not all of them in C
body: <p><strong>So here's what I need to accomplish:</strong></p>
  
  <ul>
  <li>Enter a sequence of whole numbers that end with 0</li>
  <li>Out of those numbers - calculate its square root and check if it's an odd or even number.</li>
  <li>Make use of while or do-while loops in the process.</li>
  </ul>
  
  <p>I have my no. of elements set to 4 for now, but no matter what number I set, <strong>roughly half of them come out as garbage values</strong> in the end. </p>
  
  <p>I assume this is a pointer related issue or a memory leak somewhere, I'm just not sure. Any input would be appreciated</p>
  
  <pre><code>    int num_of_elements = 4;
  
  //function declarations
  int* check_num(int i, int number[num_of_elements]);
  
  //main function
  int main() {
  
  
      //local variables
      int num[5];
      int i;
  
      printf("\nEnter a number that ends with 0");
  
      for (i=0;i&lt;num_of_elements;i++) {
          do {
              printf("\n%d.Enter a number: ", i+1);
              scanf("%d", &amp;num[i]);
          } while (num[i] % 10 != 0);
  
          printf("\nElement %d: %d\n", i+1, num[i]);
      }
  
      int j = 0;
  
      while (j&lt;num_of_elements) {
          check_num(j, &amp;num[j]);
          j++;
      }
  
      return 0;
  }
  
  //function that takes the square root and checks if it's an odd or even number
  
  int* check_num(int j, int number[num_of_elements]) {
  
      int val;
  
      printf("\nnumber[%d] is %d",j,number[j]);
  
      val = sqrt(number[j]);
      printf("\nsquare root is is %d", val);
  
          if (val % 2 == 0) {
              printf("\n%d is a an even number squared", number[j]);
          } else {
              printf("\n%d is an odd number squared", number[j]);
          }
      printf("\n");
  
      return number;
  }
  </code></pre>