[商管] 103 成大會計 DS

看板Grad-ProbAsk作者 (雨中回憶)時間11年前 (2014/12/29 02:28), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
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
return的還是a
12/29 20:40, 1F

12/29 20:43, , 2F
你ptr再怎麼更動 不影響a的部分
12/29 20:43, 2F

12/29 21:19, , 3F
喔喔!! 感謝解答 看懂問題點了
12/29 21:19, 3F
文章代碼(AID): #1Ke4lbsh (Grad-ProbAsk)