You are viewing a single comment's thread. Return to all comments →
Beware coders, g++ (likely the compiler being used here) allows variable length arrays. However, if you compile using g++ -pedantic, it will not compile because ISO C++ forbids variable length arrays. Typically array length is specified at compile time. This is a g++ extension to the language vs standard c++.
There is a solution using std::vector (std::vector allows run-time dynamic array length)
I did the variable array length solution, and tried compiling it with clang++, that worked fine as well.
Thanks for clarifying. I had thought that specifying the size of an array at runtime was not allowed in C++, but then I was second-guessing myself because the code compiled and ran fine.
Thank you for explaining this. I was very confused as to why the compiler let me get away with declaring an array size via a variable, instead of forcing me to make a call to new.