看板 C_and_CPP 關於我們 聯絡資訊
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