I found out that if you dynamically allocate the memory, it works fine because the size of a static array must be initialized or defined at compile time, while at runtime, the values of your variables have already been assigned a value and so the size of the array is known.