title: function returning pointer: max value in c++
body: <p><img src="https://i.stack.imgur.com/m3zKn.png" alt="enter image description here"></p>
  
  <p>I made that task but it turn to me a huge number not the maximum </p>
  
  <p>my code is </p>
  
  <pre><code>    #include &lt;iostream&gt;
      using namespace std;
      int* max(int p[],int n);
     int main (){
       int n;
       int*A=new int;
  
  
  int *p;
  
  cout&lt;&lt;"enter the value of array";
  cin&gt;&gt;n;
  p=new int[n];
  for(int i=0;i&lt;n;i++){
  cout&lt;&lt;"enter the element";
  cin&gt;&gt;p[n];
  }
  A=(max(p,n));
  cout&lt;&lt;"the maximum is"&lt;&lt;*A;
  return 0;
  
  }
  int* max(int p[],int n)
  {
     int maximum;
     maximum = p[0];
     for(int x=0;x&lt;n;x++)
     {
         if(p[x]&gt;maximum)
         {
             maximum=p[x];
             return &amp;maximum;
         }
     }
  
     return  &amp;maximum;
  }
  </code></pre>