The length of an array must be known at compile time. The length cannot be defined at a later time. If you insist on creating an array at some other point, use DMA. Alternatively, the more preferred way is the std::vector[1, Link]. By the way, the second array declaration is invalid. The compiler won't be able to determine the length of the array.
Like I said, either use DMA or std::vector. Either one will work, but DMA has its risks. Use DMA if the array will stay the same length, or use std::vector if the array's length will change dynamically.