Test Code
char* getString(void){
char str[] = "123456";
printf("Str in getString addr:[%x] str[%c]\n", str, str[1]);
return str;
}
char* getString_sec(void){
char str[] = "133456";
printf("Str in getString addr:[%x] str[%c]\n", str, str[1]);
return str;
}
int _tmain(int argc, _TCHAR* argv[])
{
char buff[9];
char* temp = getString();
char* temp_sec = getString_sec();
printf("temp in _tmain addr:[%x] str[%c]\n", temp, temp[1]);
printf("temp in _tmain addr:[%x] str[%c]\n", temp, temp[1]);
printf("temp in _tmain addr:[%x] str[%c]\n", temp_sec, temp_sec[1]);
return 0;
}
Test Result
Str in getString addr:[41f684] str[2]
Str in getString addr:[41f684] str[3]
temp in _tmain addr:[41f684] str[3]
temp in _tmain addr:[41f684] str[]
temp in _tmain addr:[41f684] str[]