P不会是NULL
int main()
{
if (p == NULL)
{
cout<<"P is NULL"<<endl;
}
else
{
cout<<"error "<<endl;//这步将被执行
}
return 0;
}
int main()
{
int *p;//p 默认指向oxcccccccc
p = (int *)malloc(0);//P指向ox003960co , 效果同p = (int *)malloc(1)
if (p == NULL)
{
cout<<"P is NULL"<<endl;
}
else
{
cout<<"error "<<endl;//这步将被执行
}
return 0;
}
本文深入探讨了C++中指针的使用及其内存管理机制,通过实例展示了如何正确分配和释放内存,避免常见错误,确保程序运行稳定。
1756

被折叠的 条评论
为什么被折叠?



