C language function in the release of a local variable pit

First, the code Tieshanglai:

#include <stdio.h>
#include<windows.h>
int f(int **iptr){
    int a = 100;
    *iptr = &a;
    return 0;
}

int main() {
int x = 7;
int *n;
int **m;
n=&x;
m=&n;
printf("m: %d\n",**m);
f(m);
printf("m: %d\n",**m);
Sleep(1000);
printf("m is %d\n",**m);
return 0;
}

Then I put the results of the implementation of Tieshanglai:

 

 Is boxed red color place is a pit.

This double ** m pointer points to become the value is changed in the function f 100, but executed after the end of the function f, ** m pointed variable a is released. The results become zero.

The compiler environment is mingw -w64

 

 

 

Guess you like

Origin www.cnblogs.com/kgtone/p/11787249.html