In C++ books, array bound must be constant expression, but why the following code works?

#include <iostream>
using namespace std;

int main(){
    int n=10;
    int a[n];

    for (int i=0; i<n; i++) {
        a[i]=i+1;
        cout<<a[i]<<endl;
}
    return 0;
}

worked fine in Xcode4 under Mac

as said in books, it should be wrong, why?

so confused~

9
задан f1chen 10 May 2011 в 08:59
поделиться