I´m a bit confused with these 2.
I have a function called check that does the following:
bool check(const char *word)
{
char newWord[LENGTH + 1] = "";
for (int i = 0; word[i]; i++)
{
newWord[i] = tolower(word[i]);
}
}
Now for example if I use =""
, the variable newWord
will have all of it´s values as '\0'
anytime I run the function check();
But when using char newWord[LENGTH + 1];
the variable seems to keep the old values even after my functions has returned, so when I do check()
again, the char newWord
already has values from the previous time I ran that function.
I know this is related to pointers and memory allocation but I just cannot seem to get how this works.