title: Why am I getting an unexpected output?
body: <p>I have written a code to add the elements of an array using pointers but I can't get the expected output.</p>
  
  <p>I have written the code in C as well as C++ language using exactly the same functions but i am getting the expected output from the C++ code but the code using C doesn't gives me the correct output. </p>
  
  <pre><code>void sum(int *array, int length)
  {
      int i,sum_of_array=0;
      for(i=0;i&lt;length;i++)
      {
          sum_of_array=sum_of_array+ *(array+i);
          printf("%d",sum_of_array);
      }
  }
  
  int main()
  {
      int array[]={-1,0,0,0,1,-1};
      sum(array,6);
      return 0;
  }
  </code></pre>
  
  <p>The result that I am receiving is <code>-1-1-1-10-1</code>,but the expected result should be -1.
  Kindly help me with the bug.</p>