title: Passing scalar and array data in C++ with pointers
body: <p>I have programmed for many years in FORTRAN and am trying to learn C++ and transfer some old programs to C++.  I need to be able to create an array in the function and pass it back to the main program as a variable using a pointer as opposed to having it transferred as a value as is traditional in C++.  I am including an example in this question where the variables <code>*var1</code>, <code>*varr</code> and <code>*array</code> are created and the data is passed back to the main program and this program works fine.  However, if I turn <code>*array</code> into <code>*array[1]</code> or a larger dimension array with multiple values the program does not work.  Can this action be completed in C++ or am I forced to incorporate this function into the main program so that the data is available in the main program?  Any help would be greatly appreciated!</p>
  
  <p>first example(this one works)</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  void test(int *var1,int *varr, int *array);
  
  int main()
  {
      int var,var2,array1;
      test(&amp;var,&amp;var2,&amp;array1);
      cout &lt;&lt; var &lt;&lt; "\n";
      cout &lt;&lt; var2 &lt;&lt; "\n";
      cout &lt;&lt; array1 &lt;&lt; "\n";
      return 0;
  }
  
  void test(int *var1, int *varr, int *array)
  {
      *var1=20;
      *varr=30;
      *array=15;
  }
  </code></pre>
  
  <p>second example (this one does not work)</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  void test(int *var1,int *varr, int *array[1]);
  
  int main()
  {
      int var,var2,array1[1];
      test(&amp;var,&amp;var2,&amp;array1[1]);
      cout &lt;&lt; var &lt;&lt; "\n";
      cout &lt;&lt; var2 &lt;&lt; "\n";
      cout &lt;&lt; array1 &lt;&lt; "\n";
      return 0;
  }
  
  void test(int *var1, int *varr, int *array[1])
  {
      *var1=20;
      *varr=30;
      *array[1]=15;
  }
  </code></pre>