当我研究一些与内存泄漏相关的东西时,我偶然发现了这个问题.
int* Function()
{
int arrays[10];
/* Some code here */
return &(arrays[0]);
}
Run Code Online (Sandbox Code Playgroud)
作者说上面的代码是有效的,但是返回的内存将被你调用的下一个函数重用,因此相同的内存将用于两个目的.这被称为"悬挂参考"并且可能导致可怕的间歇性故障,或者是老式的"一般保护故障".
如果有人能解释什么是"悬挂参考"和"一般保护错误",那将是很好的
struct m
{
int parent:3;
int child:3;
int mother:2;
};
void main()
{
struct m son={2,-6,5};
printf("%d %d %d",son.parent,son.child,son.mother);
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮忙说出为什么程序的输出是2 2 1?