I was taught that if we define array[N]
, then N
should be a const variable or a const expression. But now i find the following code can be compiled and run correctly.(I use g++ 4.8.3, if i use vs2010, there will be a compiled error:error C2057: expected constannt express)
#include<iostream>
int main()
{
int N;
std::cin>>N;
int A[N];
for(int i=0;i<N;++i)
std::cin>>A[i];
for(int i=0;i<N;++i)
std::cout<<A[i]<<" ";
return 0;
}
Obviously N
is not const type. I use g++ 4.8.3