C局部变量地址返回警告

Leo*_*ues -1 c warnings local-variables

我在C中有这个功能:

static Node* newNode(void* e){
Node n={e,NULL,NULL};
return &n;
}
Run Code Online (Sandbox Code Playgroud)

在编译时,我得到以下警告,我想了解它为什么会发生:

warning: function returns address of local variable [enabled by default]
Run Code Online (Sandbox Code Playgroud)

这背后隐藏着什么样的危险?

谢谢

oua*_*uah 5

从函数返回时会破坏局部变量.返回函数后访问它们是未定义的行为,不要这样做.