title: Pointer array always generate one even out of index C++
body: <p><strong>algo.h</strong></p>
  
  <pre><code>#ifndef _algorithm_
  #define _algorithm_
  
  namespace Sorting{
    int *bubble(int *dataPass, int dataSize);
  }
  
  #endif
  </code></pre>
  
  <p><strong>algo.cpp</strong></p>
  
  <pre><code>#include "algorithm.h"
  
  int *Sorting::bubble(int *dataPass, int dataSize){
    for(int i = 0; i &lt; dataSize; i++){
      for(int j = 0; j &lt; dataSize; j++){
        cout&lt;&lt;dataPass[j+1]&lt;&lt;" &lt; "&lt;&lt;dataPass[j]&lt;&lt;endl;
        if(dataPass[j+1] &lt; dataPass[j]){
          int tmp = dataPass[j];
          dataPass[j] = dataPass[j+1];
          dataPass[j+1] = tmp;
        }
      }
    }
    return dataPass;
  }
  </code></pre>
  
  <p>I want to make a sorting library and I start with bubble sort, apparently I'm facing a problem. For instance I gave the attributes dataPass <strong>array[5] = {7,2,5,8,3}</strong> and the dataSize 5. After this function executed the returned array <strong>1,2,3,5,7</strong> Where did I make it wrong? The array doesn't have 1 but the sorted showed 1, and I figured out the 8 pushed to the index 5th, so my array became 6, I have no idea what is happened.</p>