C中的指针没有价值

发布于 2025-02-12 20:23:45 字数 100 浏览 7 评论 0原文

如果您在C中声明指针,并且不要给它一个 null 值,那么指针的内存地址仍然保留,也就是无数据接管,直到您给它一个真实值或零值。这让我思考。先感谢您:)

If you declare a pointer in C and don't give it a NULL value, then is that pointer's memory address still reserved AKA it can't be taken over by no data till you give it a real value or NUll value. This got me thinking. Thank you in advance:)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘你却要生生世世 2025-02-19 20:23:45

如果任何变量被非原始化,并且在文件范围或使用static限定符中不会声明,则其值是不确定的。如果读取具有不确定值的变量,并且该变量从未取得过地址,则尝试这样做触发未定义的行为

在实践中,这意味着它可以拥有任何值,并且该值在随后的读取中不必相同。在某些体系结构上,甚至可能是陷阱表示,其中仅读取该值可能会导致崩溃。

If any variable is left uninitialized, and it is not declared at file scope or with the static qualifier, its value is indeterminate. If a variable with an indeterminate value is read, and if that variable never has its address taken, then attempting to do so triggers undefined behavior.

In practice, this means it could hold any value, and that value need not be the same on subsequent reads. On some architectures it could even be a trap representation, where just reading the value can cause a crash.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文