Take the 2-minute tour ×  There is such code:  #include
<iostream>  int main()   int size;   std::cin >> size;    size =
size + 1;   int tab3[size];    tab3[0] = 5;   std::cout <<
tab3[0] << " " << sizeof(tab3) << std::endl;   return 0;  The
result is:  $ g++ prog.cpp -o prog -Wall -W  $ ./prog 5 24  Why
does this code even compile? Shouldn't be length of array a
constant variable?  I used g++ version 4.4.5.  share|improve
this question add comment  3 Answers  up vote 12 down vote
accepted  Variable-length arrays in C++ are available as an
extension in GCC. Compiling with all warnings should have
alerted you to that fact (include -pedantic).  share|improve
this answer +1, tho I had no idea sizeof() can also be non-
constant. If I ever thought of using sizeof() on that I'd expect
it to fail for some reason. –  Michael Krelin - hacker Nov 14
'11 at 17:55 @MichaelKrelin-hacker: again, as an extension...
VLAs require a runtime sizeof(), so it's part of the C99
standard. It's just not a very C++-type of thing. Thin