I know that initialising an array with a variable is typically impossible, but oddly enough I've found a way which sort of makes it work. Here I've written code that is supposed to create an array and add up the sum of it's elements.
You are using a language extension known as Variable Length Arrays. They are mildly evil due to how quickly they can use up the stack, and importantly, they are not standard. So yes, depending on which compiler you use and what options you use with that compiler, this code will not compile.
Also possible, though more error-prone, is to dynamically allocate the array using new. The main thing to remember when using this method is to call delete[] on the array when you are done using it.
But the std::vector alternative is a much better option.