char* testFunc14()
{
char arrStr[5] = "aaaa";
return arrStr;
}
void tc14()
{
char* pStr = testFunc14();
printf("%s\n", pStr);
}
Do you think the upper code works fine?
It will not work.
For arrStr is useless out of testFunc14().
So, pStr has no data.
By the way, how about the case below?
void testPrint(char* pStr)
{
printf(pStr);
}
int tc17()
{
char arrStr[5] = "aaaa";
testPrint(arrStr);
return 1;
}
It works fine. In other words, in case of an inner function, stack array is valid.
'Papers > programming' 카테고리의 다른 글
Downcasting: C++ vs. Java (0) | 2013.12.02 |
---|---|
declare an object in switch logic (0) | 2013.11.21 |
void pointer (0) | 2013.11.21 |
constructor & destructor calling in inheritance (0) | 2013.11.19 |
What is the difference between singleton and static class? (0) | 2013.07.16 |