title: Getting errors trying to return a 2D array from a function
body: <p>I'm working on a program to find pathways in undirected graphs, and I'm using a specific function to return a 2D array of ints. The problem is, though, that I can't figure out how to make one of the dimensions' size determined at run time. When I try to leave the function declaration as</p>
  
  <pre><code>int prim(int in[][3], int nsteps, int nedges);
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>error: incompatible types in assignment of ‘int’ to ‘int [(((sizetype)(((ssizetype)(nvertex + -1)) + -1)) + 1)][3]’
       ov = prim(v, nvertex-1, nedge);
  </code></pre>
  
  <p>Changing it to</p>
  
  <pre><code>int prim[][3](int in[][3], int nsteps, int nedges);
  </code></pre>
  
  <p>gives me this error instead:</p>
  
  <pre><code>p5.cpp:23:4: error: expected unqualified-id before ‘[’ token
  int[][3] prim(int in[][3], int nsteps, int nedges);
     ^
  </code></pre>
  
  <p>I can't figure out for the life of me how to get this to work. I'd appreciate some help. Here's relevant snippets of the code:</p>
  
  <pre><code># include &lt;iostream&gt;
  # include &lt;fstream&gt;
  # include &lt;string&gt;
  using namespace std;
  
  int crimMin(int in[][3], int nsteps, int nedges);
  
  int crimMax(int in[][3], int nsteps, int nedges);
  
  int prim(int in[][3], int nsteps, int nedges);
  
  int main(int argc, char** argv){
  </code></pre>
  
  <p>Skipped most of main, this is the relevant portion</p>
  
  <pre><code>else if (x == cmax){
  for (i = 0; i &lt; nvertex-1; i++){
      if (v[i][2] == 1) v[i][2] = 0;
      else if (v[i][2] == 0) v[i][2] = 1;
  }
  ov = prim(v, nvertex-1, nedge);
  for (i = 0; i &lt; nvertex-1; i++){
      if (ov[i][2] == 1) ov[i][2] = 0;
      else if (ov[i][2] == 0) ov[i][2] = 1;
  }
  for (i = 0; i &lt; nvertex-1; i++){
      cout &lt;&lt; ov[i][0] &lt;&lt; " " &lt;&lt; ov[i][1] &lt;&lt; " ";
      if (ov[i][2] == 1) cout &lt;&lt; "C" &lt;&lt; endl;
      else if (ov[i][2] == 0) cout &lt;&lt; "W" &lt;&lt; endl;
  }
  return 0;
  </code></pre>
  
  <p>Then later down at my definition...</p>
  
  <pre><code>int prim(int in[][3], int nsteps, int nedges){
      int step = 0, curr = 0;
      int i;
      int out[nsteps][3];
      int unvisited[nsteps];
      for (i = 0; i &lt; nsteps; i++) unvisited[i] = 1;{
      //Building the output...
      }
      return out;
  }
  </code></pre>