ç悬摆指针问题 [英] C dangling pointer question

查看:118
本文介绍了ç悬摆指针问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

char *xyz()
{
   char str[32];
   strcpy(str,"Hello there!");
   return(str);
}


void main()
{
  printf("%s",xyz());
}

当我叫某某()时,它会​​返回一个悬空指针?
谢谢

When I call xyz(), is it will return a dangling pointer ? Thanks

推荐答案

是的,这是一个悬摆指针。你的程序调用未定义的行为。

Yes, it is a dangling pointer. Your program invokes undefined behaviour.

在某些系统中它可能会崩溃您的应用程序,别人就可能会出现正常工作。但无论哪种方式,你不应该这样做。

On some systems it might crash your application, on others it might appear to work correctly. But either way, you should not do it.

这篇关于ç悬摆指针问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆