[商管] 103 成大會計 DS
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的字串?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.231.106.251
※ 文章網址: http://www.ptt.cc/bbs/Grad-ProbAsk/M.1419791333.A.DAB.html
→
12/29 20:40, , 1F
12/29 20:40, 1F
→
12/29 20:43, , 2F
12/29 20:43, 2F
→
12/29 21:19, , 3F
12/29 21:19, 3F