我有这样的代码:C'S未定义行为
#include <stdio.h>
#include <math.h>
int *fun();
int main()
{
int *t;
t=fun();
printf("%d\n",*t);
printf("%d\n",*t);
}
int *fun()
{
int r=95;
return(&r);
}
这段代码中的代码块中显示的输出
95
-2
我不知道为什么第二printf()
正在打印垃圾的价值。有人可以解释一下吗?
使用原型声明器!并启用编译器警告。 – Olaf
通过在答案指出缺失后编辑'int fun()' - >'int * fun()',否定答案的值。更好地1)恢复编辑。 2)如果需要,附上一张纸条,承认这个问题并需要继续帮助。 – chux
请告诉我们,当你编译这个时,你得到了什么警告。 –