c++野指针问题

曾经的洒脱 曾经的洒脱 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
typedef unsigned short int USHORT;

#include <iostream>

int main()
{
USHORT *pInt = new USHORT;
*pInt = 10;

std::cout << "*pInt " << *pInt << std::endl;
delete pInt;

long *pLong = new long;
*pLong = 90000;
std::cout << "*plong: " << *pLong << std::endl;

*pInt = 20;
std::cout << "*pInt: " << *pInt << std::endl;
std::cout << "*pLong: " << *pLong << std::endl;

std::cout << "pInt: " << pInt << std::endl;
std::cout << "pLong: " << pLong << std::endl;
delete pLong;
return 0;
}


程序代码,如上所示。程序最后两句会打印相同的地址值,在整个程序中,指针变量是没有改变的,既然如此,那么程序的倒数3、4行的打印为什么不是同一个值??
...全文
评论 14
收藏 已收藏
分享
返回顶部
曾经的洒脱
C++ 语言 65,214 成员 250,514 内容