【发布时间】:2014-03-24 23:56:15
【问题描述】:
我通过一些网站搜索并找到了一个悬挂指针的程序。我找到了一个在 TC 中完美执行的最佳程序。但是由于我对 fflush(stdin) 的怀疑,我无法理解程序的全部含义。所以请说出以下程序的含义和其他程序:
#include<stdio.h>
int *call(void);
int main(void) {
int *ptr;
ptr = call();
fflush(stdin);
printf("%d", *ptr);
return 0;
}
int *call(void) {
int x = 25;
++x;
return &x;
}
【问题讨论】:
-
没有@Banthar。这个问题并不具体。但我的疑问特别是在上面的程序中。
-
也是UB,因为它返回并使用自动变量的地址。