title: Returning pointers from function gives weird numbers
body: <p>Iam trying to get the max number of this array that has numbers from -20 to 30 but it returns weird numbers like this --> 2255667 which is impossible if all is going well.</p>
  
  <pre><code>int * ptomx(int a[],int n)
  {
    int max=-100;
    int *point;
  
    for(int i=0;i&lt;=n;i++)
    {
        if(max&lt;a[i])
        {
          max = a[i];
        }
    }
    point = new int;
   *point = max;
    return point;
  }
  </code></pre>
  
  <p>This is what i do in main()</p>
  
  <pre><code>int maxTemp;
  
  maxTemp=*(ptomx(a,n));
  
  cout&lt;&lt;"Max temp is:"&lt;&lt;maxTemp;
  </code></pre>
  
  <p>Is it because the pointer in the function is destroyed after the function returns and gives a random number in that memory location. If thats the case it needs to be dereferenced but how? </p>