title: C++ correct way to return pointer to array from function
body: <p>I am fairly new to C++ and have been avoiding pointers. From what I've read online I cannot return an array but I can return a pointer to it. I made a small code to test it and was wondering if this was the normal / correct way to do this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int* test (int in[5]) {
      int* out = in;
      return out;
  }
  
  int main() {
      int arr[5] = {1, 2, 3, 4, 5};
      int* pArr = test(arr);
      for (int i = 0; i &lt; 5; i++) cout&lt;&lt;pArr[i]&lt;&lt;endl;
      cout&lt;&lt;endl;
      return 0;
  }
  </code></pre>
  
  <hr/>
  
  <p><strong>Edit</strong>: This seems to be no good. How should I rewrite it?</p>
  
  <pre><code>int* test (int a[5], int b[5]) {
      int c[5];
      for (int i = 0; i &lt; 5; i++) c[i] = a[i]+b[i];
      int* out = c;
      return out;
  }
  </code></pre>