char * ptr;
ptr=(char*)malloc(0);
if(ptr==NULL)
{
cout<<"it is a null pointer"<<endl;
}
else
{
cout<<"it is a non-null pointer"<<endl;
cout<<"the length is "<<sizeof(ptr)<<endl;
cout<<"the strlen is "<<strlen(ptr)<<endl;
}
输出结果:it is a non-null pointer
the length is 4
the strlen is 16
把0传给malloc,可以得到一个合法的指针。
阅读(863) | 评论(0) | 转发(0) |