Here's the code:
Compiler error is:Code:unsigned int* generatePopulation(const int); int main(){ const int POPSIZE = 3; unsigned int* population; population = generatePopulation(POPSIZE); } unsigned int* generatePopulation(const int size){ static int population[size]; //...fill the array return population; }
I've searched the error and people recommend that a variable defined with const is still a "variable", however, compiler needs a constant created with #define processor for the size of a static array, however, I can not do this, since I want to get the input from the outside(e.g. using scanf) so a preprocessor command won't help, also the array has to be static or else it will be destroyed after the function call. Is there a way for it? Thanks in advance.Code:error: storage size of ‘population’ isn’t constant