title: Finding Max, Min, Avg using dynamic memory allocation and pointers
body: <p>I am learning pointers so I tried to implement this simple code of finding Max, min and Avg of student grades.
  I only could found the <em>avg</em> <strong>BUT</strong> for the <em>Max</em> and the <em>Min</em> I got the first element of the <code>*p</code>.</p>
  
  <p>here is my code <strong>If you please can tell me what is my mistake</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      int *p;
      int x;
  
  cout &lt;&lt; "Enter a number of student: ";
  cin &gt;&gt; x;
  p = new int[x];
  
  for (int i = 0; i &lt; x; i++)
  {
      cout &lt;&lt; "Enter a grade: ";
      cin &gt;&gt; *(p + i);
  }
  int sum = 0;
  int max = 0;
  int min = 0;
  max = *p;
  min = *p;
  
  for (int i = 0; i &lt; x; i++)
  {
      if (min &gt; *p)
      {
          min = *p;
          p++;
      }
  }
  
  for (int i = 0; i &lt; x; i++)
  {
      if (max &lt; *p)
      {
          max = *p;
          p++;
      }
  }
  
  for (int i = 0; i &lt; x; i++)
  {
      sum += *p;
      p++;
  }
  int avg = sum / x;
  cout &lt;&lt; "avg is : " &lt;&lt; avg &lt;&lt; endl;
  cout &lt;&lt; "Max num is : "&lt;&lt; max 
       &lt;&lt; "\n Min num is : " &lt;&lt; min &lt;&lt; endl;
  </code></pre>
  
  <p>}</p>