title: Array passed as arguement to a function showing garbage values
body: <p>here's the code:</p>
  
  <pre><code>int *num_arr = number_to_array(num);
  cout&lt;&lt;"\nNum aaray:"&lt;&lt;*(num_arr+1);
  display(num_arr, digit_count);
  </code></pre>
  
  <p>The cout statement here is showing the correct value, but display() is not. display is showing garbage values</p>
  
  <p>code for display():</p>
  
  <pre><code>void display(int num_arr[],int dc)
  {
  cout&lt;&lt;"\n";
  cout&lt;&lt;"\n"&lt;&lt;num_arr[0];
  cout&lt;&lt;"\n"&lt;&lt;num_arr[1];
   for(int i = (dc-1); i&gt;=0; i--)
   {
           cout&lt;&lt;num_arr[i];
   }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>int* number_to_array(int num)
  {
  int i=0;
  int num_arr[100]; // make dynamic array
    while(num!=0)
    {
      num_arr[i] = num%10;
      num  = num/10;                
      i++;
     }
  return num_arr;
  }
  </code></pre>
  
  <p>what could be the reason?</p>