Declaring the array size with a non-constant variable Declaring the array size with a non-constant variable arrays arrays

Declaring the array size with a non-constant variable


This is a GCC extension to the standard:

You can use the -pedantic option to cause GCC to issue a warning, or -std=c++98 to make in an error, when you use one of these extensions (in case portability is a concern).


You are using a feature from C99 which is called VLA(variable length arrays). It would be better if you compile your program like this:

g++ -Wall -std=c++98 myprog.cpp