I'm trying to make a function that creates a personalized array and return the pointer to it. I've the following code:
int (*newArray())[COLUNAS] {
static int thisIsTheNewArray[LINHAS][COLUNAS];
/* some changes */
return thisIsTheNewArray;
}
Then, I have:
int (*tabuleiroJogador)[COLUNAS] = newArray();
int (*tabuleiroComputador)[COLUNAS] = newArray();
The problem here is that if I change tabuleiroJogador
I also change tabuleiroComputador
. I don't know why this is happenning. I think it's related with the static
keyword and it returns always the same instance.
The arrays should be different.