malloc(0)返回是什么?
测试代码如下:
#include <stdio.h> #include <stdlib.h> int main(void) { int* nptr = NULL; printf("%p ", nptr); if( nptr == NULL ) { printf( "现在是空的\n" ); } nptr = malloc(0); printf("用malloc(0)赋值之后\n"); printf("%p ", nptr);//地址的输出格式是%p if( nptr != NULL ) { printf( "现在不是空的\n" ); } return 0; }
运行结果是:
说明:malloc(0)返回的并不是NULL指针