title: C++ functions returning arrays
body: <p>I am sort of new to C++. I am used to programming in Java. This particular problem is causing me great issues, because C++ is not acting like Java when it is dealing with Arrays. In C++, arrays are just pointers.</p>
  
  <p>But why does this code: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #define SIZE 3
  using namespace std;
  
  void printArray(int*, int);
  int * getArray();
  int ctr = 0;
  
  int main() {
    int * array = getArray();
  
    cout &lt;&lt; endl &lt;&lt; "Verifying 2" &lt;&lt; endl;
    for (ctr = 0; ctr &lt; SIZE; ctr++)
      cout &lt;&lt; array[ctr] &lt;&lt; endl;
  
    printArray(array, SIZE);
    return 0;
  }
  
  int * getArray() {
    int a[] = {1, 2, 3};
    cout &lt;&lt; endl &lt;&lt; "Verifying 1" &lt;&lt; endl;
    for (ctr = 0; ctr &lt; SIZE; ctr++)
      cout &lt;&lt; a[ctr] &lt;&lt; endl;
    return a;
  }
  
  void printArray(int array[], int sizer) {
    cout &lt;&lt; endl &lt;&lt; "Verifying 3" &lt;&lt; endl;
    int ctr = 0;
    for (ctr = 0; ctr &lt; sizer; ctr++) {
      cout &lt;&lt; array[ctr] &lt;&lt; endl;
    }
  }
  </code></pre>
  
  <p>print out arbitrary values for verify 2 and verify 3. Perhaps this has something to do with the way arrays are really handled as pointers.</p>