代码段如下:
#include <stdio.h>
#include <stdlib.h>
int* noMalloc();
int main()
{
int *a = noMalloc();
printf("%d ", *a);
return 0;
}
int* noMalloc()
{
int b;
b = 100;
return &b;
}
运行结果
我觉得noMalloc()函数里面的局部变量b在调用函数之后就被释放了,即使得到返回b的地址,也不会得到原来的值吧?
我以为会输出a会得到随机值或者别的意想不到的结果,然而运行时a的值就是100,为什么?不理解.