free指针后,指针会指向NULL吗
时间: 2023-11-02 22:52:25 浏览: 137
在释放指针后,指针本身不会自动指向NULL。这是因为在释放指针时,只是将指针指向的内存释放掉,并没有将指针本身置为NULL。所以,释放指针后,指针仍然指向之前的内存地址,这个地址现在是无效的,也被称为野指针。为了避免出现乱指的情况,我们应该在释放完指针后,立即将指针置为NULL,防止误用野指针。\[1\]\[2\]\[3\]
#### 引用[.reference_title]
- *1* [C++中指针free/delete后为什么要刻意指向NULL](https://blog.csdn.net/Rolandxxx/article/details/126035120)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [【C语言】5. 指针free后为什么要刻意指向NULL、野指针(原因、解决)、悬垂指针](https://blog.csdn.net/WL0616/article/details/122650576)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文