usage of double pointers as arguments

后端 未结 4 2060
北海茫月
北海茫月 2021-01-13 22:33

Please find the code snippet as shown below:

#include  

int My_func(int **); 

int main() 
{ 
     int a =5;
     int *p = &a;
     My_Fu         


        
4条回答
  •  臣服心动
    2021-01-13 23:20

    You are assigning the address of local variable, which will soon disappear when My_Func returns. You can use following in your code. However you can do the same thing just by using single pointer, double pointer is not required in this example.

    void My_Func(int **p)
    {
         int val = 100;
         int *Ptr = &val;
         **p = *Ptr;
    }
    

提交回复
热议问题