title: What does int i do inside of the for loop(in scanf and sum) in this particular program?
body: <p>Isn't <code>i</code> in <code>scanf</code> and in <code>sum</code> useless? It doesn't change anything, even when I print <code>&amp;ptr</code> it doesn't show me any difference in memory values.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main() {
      int n, *ptr, sum = 0;
  
      printf("Enter number of elements: ");
      scanf("%d", &amp;n);
  
      ptr = (int *)malloc(n * sizeof(int));
  
      // if memory cannot be allocated
      if (ptr == NULL) {
          printf("Error! memory not allocated.");
          exit(0);
      }
  
      printf("Enter elements: ");
      for (int i = 0; i &lt; n; ++i) {
          scanf("%d", ptr + i);
          sum = sum + *(ptr + i);
      }
  
      printf("Sum = %d", sum);
  
      // deallocating the memory
      free(ptr);
  
      return 0;
  }
  </code></pre>