#include <stdio.h>
#include <stdlib.h>
int *func(void)
{
int a=2; //a是局部变量,也叫临时变量;
printf("&a=%p\n",&a);
return &a; //函数不能返回函数中局部变量的地址,因为函数执行完系统释放局部变量;
}
void fun1(void)
{
int a=34;
int b=9;
int c=98;
}
int main(void)
{
int *p=NULL;
p=func();
fun1();
printf("a=%d",*p); // 那为什么还可以访问呢?因为局部变量被释放了,但是栈的内存还在;
//再次访问时,栈的地址与原来的变量无关了。
return 0;
}