作者timlong (timlong)
看板C_and_CPP
標題Re: [問題] malloc問題
時間Sun Mar 15 22:10:32 2009
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)
推 peiga:我懂了,alloc_mem()的參數是指標的指標,會接受ptr的位址 03/15 23:32
→ peiga:然後alloc_mem()裡的*p會把ptr裡的值指向malloc() 03/15 23:33
→ peiga:謝謝所有指導的前輩! 03/15 23:33