我有兩個函數具有相同的返回類型:爲什麼這個類似的函數不會拋出相同的錯誤?
char * getRandomWord(char wordlist[WORDLIST_LENGTH][WORD_LENGTH]) {
int random = rand() % WORDLIST_LENGTH;
return wordlist[random];
}
char * revealInString(char * s, int * r) {
size_t strLength = strlen(s);
char revealedString[strLength + 1];
for (int i = 0; i < strLength; i++) {
revealedString[i] = '_';
}
for (int i = 0; i < strLength; i++) {
if (r[i] != NULL) {
int positionToReveal = r[i];
revealedString[positionToReveal] = s[positionToReveal];
}
}
revealedString[strLength - 1] = '\0';
return revealedString;
}
的第一個作品沒有問題,而我的IDE(克利翁)顯示了第二個問題:Value escapes the local scope
。
爲什麼第二個函數顯示錯誤,而第一個函數也返回一個沒有問題的字符數組?