tamojit9's blog

By tamojit9, 13 years ago, In English
#include<iostream>
using namespace std;
main()
{
      int m;
      cin>>m;
      int re[m];
      cout<<sizeof(re);
}

This code is running perfectly in codeforces GNU C++ 4.7. But why?? shouldn't the array size be a constant.

  • Vote: I like it
  • +6
  • Vote: I do not like it

»
13 years ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Latest GCC versions seem to be able to cope with that. I was shocked as well the first time my friend claimed this is possible in GCC. I agree that it is quite misleading for beginners, because it, kind of, "violates" basic principles of "what's good and what's wrong" :)

Here is mentioned what to do if you need to have that warning. http://stackoverflow.com/questions/17899274/g-variable-size-array-no-warning