[商管] 103 成大会计 DS

楼主: isong199 (雨中回忆)   2014-12-29 02:28:50
consider the following function that returns the address of stack-allocated
local variable:
char *fun(void)
{
Char *a = "a sunny day";
char *ptr = a;
ptr = (char*)malloc(10*sizeof(char));
return a;
}
我自己的的答案是写a sunny da
不过我跑程式他是给我a sunny day
malloc不是借了10个byte为么可以跑出11个byte的字串?
作者: breeze618 (微风)   2014-12-29 20:40:00
return的还是a你ptr再怎么更动 不影响a的部分
楼主: isong199 (雨中回忆)   2014-12-29 21:19:00
喔喔!! 感谢解答 看懂问题点了

Links booklink

Contact Us: admin [ a t ] ucptt.com