Re: [問題] malloc問題

看板C_and_CPP (C/C++)作者 (timlong)時間16年前 (2009/03/15 22:10), 編輯推噓1(102)
留言3則, 1人參與, 最新討論串3/6 (看更多)
void alloc_mem(int **p) { *p = (int *)malloc(sizeof(int)); } int main() { int *ptr=NULL; alloc_mem(&ptr); /*...*/ } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.113.79.102 ※ 編輯: timlong 來自: 59.113.79.102 (03/15 22:12)

03/15 23:32, , 1F
我懂了,alloc_mem()的參數是指標的指標,會接受ptr的位址
03/15 23:32, 1F

03/15 23:33, , 2F
然後alloc_mem()裡的*p會把ptr裡的值指向malloc()
03/15 23:33, 2F

03/15 23:33, , 3F
謝謝所有指導的前輩!
03/15 23:33, 3F
文章代碼(AID): #19lGnPj4 (C_and_CPP)
討論串 (同標題文章)
以下文章回應了本文
完整討論串 (本文為第 3 之 6 篇):
2
3
1
6
文章代碼(AID): #19lGnPj4 (C_and_CPP)