二级指针作为形参的套路

//通常主函数会这么调用:
int main(){
    int * a = NULL;
    //此处传入的是指针的地址,也就是指针的指针
    getNum(&a);       
    return 0; 
}
 void getNum(int ** a){
  //在这里,我们假设要传回一个size为5的a
  *a = (int *)malloc(sizeof(a)*5) ;
  for(int i = 0;i<5;i++){  
    (*a)[i]=i;
  }
}

猜你喜欢

转载自www.cnblogs.com/geooeg/p/9690224.html