NULL是C语言中的一个特殊指针,它相当于数字0的指针,在C头文件中有如下定义:
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
cplusplus是cpp中自定义的一个宏,如果定义了这个宏则定义NULL为0,否则定义NULL为定义为((void*)0)。
给指针赋予0值时,就等于将它设为NULL,常常遇到这样的语句:
pVaule=int* fun(parameter1,parameter2......);
if(!pValue)
{
///statement
}
如果pValue是NULL,则!pValue就是true,所以上述语句pValue是NULL时才会执行。
或者将上述语句写为:
pValue=int* fun(parameter1,parameter2..........)
if(pValue==NULL)
{
//statement.........
}
第一次尝试代码片,哈哈哈、、、、、、、、
pVaule=int* fun(parameter1,......);
if(!pValue)
{
///statement
}