Is declaring a local array based on function arguments legal in c++
<p>I read from a book saying that the following c++ code should not compile:</p>

<pre><code>  void f(int n, int m){
     int a[n] , b[n][m];
  }
</code></pre>

<p>because the size of the arrays are not determined at compile time.</p>

<p>But I tried it out and found no matter the function is a global one or a member function, I could get compilation successful using g++.</p>

<p>Was this something made legal in recent c++ implementation, or the book is simply wrong.</p>

<p>Thank you.</p>

<p><strong>Edit</strong></p>

<p>I saw a few replies immediately. I just have this wonder too in Java. I notice in java, this is supported (please correct me if this is also version dependent). So why the difference? Does it have anything to do with using references vs. objects? But still, in java, I can declare an array with variable length from function argument for primitives.</p>

<p><strong>Edit 2</strong></p>

<p>The following Java code did compile though, if you say it should not:</p>

<pre><code>class Test1 {
    public int[] f(int n,int k){
        int[] c=new int[n];
        Arrays.fill(c, k);
        return c;
    }
}
</code></pre>
