Why doesn't this loop correctly fill a 2D array (c++)? : <p>this code</p>

<pre><code>int rows;
int cols;
cout &lt;&lt; "enter desired columns of matrix" &lt;&lt; endl;
cin &gt;&gt; cols;
cout &lt;&lt; "enter desired rows of matrix" &lt;&lt; endl;
cin &gt;&gt; rows;
int matrix[cols][rows];
cout &lt;&lt; "begin entering values row by row" &lt;&lt; endl;
for(int i = 0; i &lt; cols; i++)
    for(int j = 0; j &lt; rows; j++){
        cin &gt;&gt; matrix[i][j];
}
</code></pre>

<p>produces this output</p>

<pre><code>enter desired width of matrix
10
enter desired height of matrix
10
begin entering values
1
1

RUN SUCCESSFUL (total time: 4s)
</code></pre>

<p>Why don't the nested for loops iterate through the array row by row, getting input for each element?  Also, if the first '1' is the input I typed, what is the second '1' that is output on the last line just prior to termination?</p>
