usage of double pointers as arguments

后端 未结 4 2092
北海茫月
北海茫月 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:15

    Use it in the function declaration:

    void func(int *p)
    {
      int val =100;
      int *temp=&val;
      p=temp;
     }
    

    p starts pointing to another address i.e. address of val. So it will print the value 100.

    Important note: Try it in your downloaded compiler (always in case of pointers) not in the online compiler. The online compiler doesn´t keep track of lost addresses in stack.

提交回复
热议问题