title: An array passed to a function gives nan elements (C++)
body: <p>I have a function that takes in an array and defines a new array made up of a subset of the original array.</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;cmath&gt;
  using namespace std;
  double * subarray(double *array){
         double *sub= new double[100]; 
         for (int i=0; i&lt;10; i++){
           sub[i]=array[i];
         }
      return sub;
  }
  int main(){
    double *x=new double[100];
    double *y=new double[10];
  
    for(int j=0; j&lt;100; j++){
       x[j]=sin(j*3.14/2.0);
    }
    y=subarray(x);
    for(int k=0; k&lt;10; k++){
       cout&lt;&lt;y[k]&lt;&lt;endl;
    }
  return 0;
  } 
  </code></pre>
  
  <p>When I run this code some of the elements of the sub array come out as nan. </p>