[討論] run time error 相關的問題

看板C_and_CPP (C/C++)作者 (阿德)時間10年前 (2016/02/24 02:16), 編輯推噓2(201)
留言3則, 2人參與, 最新討論串1/1
這是我的片段的 code main 中的 片段 code int *ans=find(m,n,letter_query); printf("%d %d\n",ans[0]+1,ans[1]+1); int *find(int m,int n,char *letter_query) { int ans[2] ..... ...... return ans } 我解uva online jundge 以上是我片段的程式碼 然後 response 是 run time error 但是我把 ans array 宣告成global變數 就AC 為什麼會這樣子 而且我的complier 沒當調 是我丟上去 uva online judge 才 response run time error message 為什麼會這樣子 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.122.100.231 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1456251395.A.78B.html

02/24 02:25, , 1F
你return了local 變數的address了 "ans"
02/24 02:25, 1F

02/24 12:05, , 2F
local變數跳出function就沒了,你回傳的address裡面的資
02/24 12:05, 2F

02/24 12:05, , 3F
料不一定會正確
02/24 12:05, 3F
文章代碼(AID): #1MpA83UB (C_and_CPP)
文章代碼(AID): #1MpA83UB (C_and_CPP)