把代码过程较好的一些代码珍藏起来,下面的代码是关于C语言面试题:与malloc(0)相关的问题,附答案和详解的代码。
#include<stdio.h>
#include<stdlib.h>
{
{
printf(“is null pointern”);
printf(“pointer:%pn”,pointer);
free(pointer);
}
else
{
printf(“is valited pointern”);
printf(“pointer:%pn”,pointer);
free(pointer);
}
return 0;
}
malloc(0)返回堆上的任意一个字节的地址,并且返回的地址空间可以对其进行操作。
运行结果:
isvalitedpointer
pointer:0x7f23adff
b